I need urgent help if someone helps me with how to populate multiple textbox from database with data using 3 tier architecture in asp.net.
Below is my code.
Code for UI code behind
protected void GetPatinfo(object sender, EventArgs e)
{
//Creating the object of BAL
txtpatname.Text = string.Empty;
string recordStatus;
string patcard = txtcardnumber.Text;
try
{
//Passing the Parameter in the Method of BAl using BAL object
recordStatus = objOPDCheck_BLL.GetPatinfo(patcard);
if (recordStatus == null)
Response.Write("Oops! No match");
else
txtpatname.Text = recordStatus;
texpid.Text = recordStatus;
}
catch (Exception ex)
{
Response.Write("Oops! No match:" + ex.Message.ToString());
}
finally
{
objOPDCheck_BLL = null;
}
}
Code for BLL
public string GetPatinfo(string patcard)
{
try
{
return objOPDCheck_DAL.GetPatinfo(patcard);
}
catch (Exception ex)
{
throw ex;
}
finally
{
objOPDCheck_DAL = null;
}
}
Code for DAL
public string GetPatinfo(string patcard)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString);
SqlCommand cmd = new SqlCommand() { CommandType = CommandType.StoredProcedure, CommandText = "get_patient2" };
cmd.Parameters.Add("@Identification", SqlDbType.VarChar).Value = patcard;
cmd.Connection = con;
con.Open();
SqlDataReader dr;
try
{
dr = cmd.ExecuteReader();
if (dr.Read())
{
return dr["Names"].ToString ();
return dr["ID"].ToString();
}
else
return dr["Names"].ToString ();
return dr["ID"].ToString();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}