Click here to Skip to main content
15,895,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 5 records in sql i have an id and name in the database

if i want to get those name and id in a label at run time..

Any Idea...
Posted

The stream of trivial questions from you is breathtaking. Why not buy a book and read it ? Tell me someone is not paying for the code you're producing ?

The label has a Text property. Set it, using data you get from the DB.
 
Share this answer
 
Here is answer for the Question Friends.. Atlast i go this...



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]);

}
}
 
Share this answer
 
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.
 
Share this answer
 

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