Click here to Skip to main content
16,020,347 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
protected void BtnCase_Click(object sender, EventArgs e)
{
if (!(IsPostBack))
{
if (Request.QueryString.HasKeys() && Request.QueryString["id"].ToString() != null)
{

SqlConnection sc = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["hospitalmanagementdb"].ToString());
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from patient where patient_id= " + Request.QueryString["id"].ToString();
cmd.Connection = sc;
sc.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
sc.Close();

txtFirstnm.Text = sdr[1].ToString();
txtLastnm.Text = sdr[2].ToString();
RadioMF.Text = sdr[3].ToString();
txtAge.Text = sdr[4].ToString();
txtContact.Text = sdr[5].ToString();
txtEmail.Text = sdr[6].ToString();
txtAddress.Text = sdr[7].ToString();


}
}
}




there is no error but data from table can not be display in form
Posted

How do you know there is no error? You aren't checking...

The most likely reasons for it not displaying anything are that it failed one of your tests:
IsPostBack could be true.
HasKeys could return false - there are no keys.
They may not be a query string "id".

In this case, I suspect IsPostBack, since it will always be true for a button click event handler...
 
Share this answer
 
Comments
Member 10694442 24-Mar-14 12:17pm    
still data can not be fetched
OriginalGriff 24-Mar-14 12:27pm    
So what is happening?
Have you used the debugger at all to look at what actually does happen?
You need to remove:
if (!(IsPostBack))
 {
 }


That is why your code is not running.

[EDIT]

Change your query to this:
cmd.CommandText = "select * from patient where patient_id= '" + Request.QueryString["id"].ToString() + "'";


This will work provided you are actually passing "id" in the query string.
 
Share this answer
 
v3
Comments
Member 10694442 24-Mar-14 12:19pm    
still data not display
Richard C Bishop 24-Mar-14 12:24pm    
Is your query returning anything?
Member 10694442 24-Mar-14 12:37pm    
no
Richard C Bishop 24-Mar-14 12:39pm    
Ok, have a look at my updated solution and use that code.
Member 10694442 24-Mar-14 13:07pm    
oh no its also not worked
C#
protected void BtnCase_Click(object sender, EventArgs e)
{
if (!(IsPostBack))
{
if (Request.QueryString.HasKeys() && Request.QueryString["id"].ToString() != null)
{
 
SqlConnection sc = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["hospitalmanagementdb"].ToString());
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from patient where patient_id= " + int.Parse(Request.QueryString["id"].ToString());  // or .... patient_id = '" + Request.QueryString["id"]+ "'";
cmd.Connection = sc;
sc.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
sc.Close();
 
txtFirstnm.Text = sdr[1].ToString();
txtLastnm.Text = sdr[2].ToString();
RadioMF.Text = sdr[3].ToString();
txtAge.Text = sdr[4].ToString();
txtContact.Text = sdr[5].ToString();
txtEmail.Text = sdr[6].ToString();
txtAddress.Text = sdr[7].ToString();

}
}
}


-KR
 
Share this answer
 
Comments
Member 10694442 24-Mar-14 15:39pm    
still data not display
Member 10694442 24-Mar-14 15:42pm    
thanks for your ans
Member 10694442 24-Mar-14 15:42pm    
i m really tired with this i cant found where the mistake is

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900