How to Write Record to a Label

Hi,

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)
        objConn.Open()


        Dim dAdapter As New SqlDataAdapter
        dAdapter.SelectCommand = New SqlCommand("SELECT * FROM tblCMS", objConn)

        Dim dSet As New DataSet
        dAdapter.Fill(dSet)

        objConn.Close()

I want to write first record “ID” to a label named “lblWelcome” in ASP.net page.

Please advice.

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 =
Convert.ToInt32(dSet.Tables[“tblCMS”].Columns[“PrimaryKeyId”].Rows[i]);

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

Thanks!