SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    PHP 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.

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,868
    Mentioned
    37 Post(s)
    Tagged
    0 Thread(s)
    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

  3. #3
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •