Hi
To bind a data from the DB in Labels I have given the coding as
public partial class SerachResult : System.Web.UI.P age
{
SqlConnection con;
SqlDataReader dr1;
string str;
string sql;
protected void Page_Load(objec t sender, EventArgs e)
{
this.Label1 .Text = Request.QuerySt ring["Name"];
str = "user id=sa;password= cast;database=H ello_Dr;server= AURORA-SERVER";
con= new SqlConnection(s tr);
con.Open();
sql = "SELECT * FROM DoctorRegistrat ion3 where Name=" + Label1.Text + "";
SqlCommand cmd = new SqlCommand(sql, con);
dr1 = cmd.ExecuteRead er();
while(dr1.Read( ))
{
Label3.Text = dr1.GetValue(14 ).ToString();
Label5.Text = dr1.GetValue(12 ).ToString();
Label7.Text = dr1.GetValue(13 ).ToString();
Label9.Text = dr1.GetValue(9) .ToString();
Label11.Text = dr1.GetValue(10 ).ToString();
Label14.Text = dr1.GetValue(18 ).ToString();
Label15.Text = dr1.GetValue(19 ).ToString();
}
}}
But when I run the project, it shows the following error
SqlException was unhandled by user code:
Incorrect syntax near 'K'.
The error showing is on the line
dr1 = cmd.ExecuteRead er();
To bind a data from the DB in Labels I have given the coding as
public partial class SerachResult : System.Web.UI.P age
{
SqlConnection con;
SqlDataReader dr1;
string str;
string sql;
protected void Page_Load(objec t sender, EventArgs e)
{
this.Label1 .Text = Request.QuerySt ring["Name"];
str = "user id=sa;password= cast;database=H ello_Dr;server= AURORA-SERVER";
con= new SqlConnection(s tr);
con.Open();
sql = "SELECT * FROM DoctorRegistrat ion3 where Name=" + Label1.Text + "";
SqlCommand cmd = new SqlCommand(sql, con);
dr1 = cmd.ExecuteRead er();
while(dr1.Read( ))
{
Label3.Text = dr1.GetValue(14 ).ToString();
Label5.Text = dr1.GetValue(12 ).ToString();
Label7.Text = dr1.GetValue(13 ).ToString();
Label9.Text = dr1.GetValue(9) .ToString();
Label11.Text = dr1.GetValue(10 ).ToString();
Label14.Text = dr1.GetValue(18 ).ToString();
Label15.Text = dr1.GetValue(19 ).ToString();
}
}}
But when I run the project, it shows the following error
SqlException was unhandled by user code:
Incorrect syntax near 'K'.
The error showing is on the line
dr1 = cmd.ExecuteRead er();
Comment