I am learning ASP.net. I connected to database but can't figure out how to write record ID to label. Below is the code:
Dim strConnection As String = ConfigurationManager.ConnectionStrings("objConn").ConnectionString
Dim objConn As New SqlConnection(strConnection)
Dim dAdapter As New SqlDataAdapter
dAdapter.SelectCommand = New SqlCommand("SELECT * FROM tblCMS", objConn)
Dim dSet As New DataSet
I want to write first record "ID" to a label named "lblWelcome" in ASP.net page.
To write a record to a label you will need a SqlDataReader and you can do whatever you like while stepping through the reader object. Well, that is the fastest way anyway.
From a dataset loop through it like this:
for (int i = 0; i < dSet.Tables["tblCMS"].Rows.Count; i++)
int lngPrimaryKeyId =
lblWelcome.Text = lngPrimaryKeyId.ToString();
But remember, this is to loop through each item. But from the above, I am sure you can figure out to just get the first item. Which will not be done in a loop.
PS. The above is in C#. My VB skills are long bug forgotten. Good luck
This topic is now archived. It is frozen and cannot be changed in any way.