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....
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hiren SoniPosted Jan 6, 2010, 11:52 AM
Lalit MPosted Jan 6, 2010, 7:24 AM
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)
Rekha SinghPosted Jan 6, 2010, 6:54 AM
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