Retrieve value from sql to label
i have name and age fields stored in sql i have two label such as labe1 labe12 and button ... i want it to retrieve the value stored in database to the label1 and label 2 .. How to do it....
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Rekha SinghRank #1,571 · 1K reputationPosted Jan 6, 2010, 1:54 AM EST
string sqlText = "select name,age from table where somrthing = something";
SqlConnection connection = new SqlConnection("ur connection string");
connection.Open();
DataSet ds = new DataSet();
SqlDataAdapter ad = new SqlDataAdapter(sqlText, connection);
ad.Fill(ds);
label1.text = ds.Tables[0].Rows[0][0];
label2.text = ds.Tables[0].Rows[0][1];
***********************
pls mark Accepted if u find it helpful
Lalit MRank #1,186 · 1.5K reputationPosted Jan 6, 2010, 2:24 AM EST
Dim cn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString1").ToString)
cn.Open()
Dim SqlCmd As SqlCommand
SqlCmd = New SqlCommand("SELECT [FirstName] FROM [Contact] WHERE CustID = 39", cn)
custIDLabel.Text = ctype(SqlCmd.ExecuteScalar,string)
Hiren SoniRank #694 · 3.5K reputationPosted Jan 6, 2010, 6:52 AM EST