ithighway — 2012-05-06T03:39:01-04:00 — #1
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.
nightstalker — 2012-05-07T02:29:40-04:00 — #2
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
ithighway — 2012-05-07T04:23:48-04:00 — #3
mittineague — 2014-09-17T23:08:08-04:00 — #4
This topic is now archived. It is frozen and cannot be changed in any way.