protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=sss;database=xyz;integrated security=true");
con.Open();
SqlCommand cmd = new SqlCommand(" select * from lab where id=" + TextBox1.Text, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Label1.Text = Convert.ToString(dr[0]);
Label2.Text = Convert.ToString(dr[1]);
}
}
Yes, this will work. However, again, PLEASE tell me that no-one is paying for this awful, poorly designed and hard to read code ? Apart from all the other issues that it has, you realise that if you put this code into production, your users can erase your database any time they like, probably create users, etc, all outside your control ?
If you're learning, that's fine. But, in that case, one would hope that you'd choose tasks that are within your reach, instead of spending weeks asking how to do the same things, over and over ? If you choose to learn at a proper pace, you will learn daily, and not struggle for weeks with the same task.