Results 1 to 7 of 7

Thread: more then one record

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    110

    more then one record

    I am trying to retrieve ten fields each from a different column in access 2007 and put them in vb.net labels. I can always mange to get the last record in the table but how can I get 10 records each from different columns?

    Code:
         Dim objconnection As New OleDbConnection(connection)
    
            objconnection.Open()
    
            Dim Sql As String = "select * From aa Where bb = 98"
    
            Dim objCommand As New OleDbCommand(Sql, objconnection)
    
            Dim objReader As OleDbDataReader
    
            objReader = objCommand.ExecuteReader
    
            If objReader.HasRows Then
                While objReader.Read
                    Label11.Text = (objReader.GetString(1))
                         End While
            End If
    Thats my code for retrieving one record how can i change it to retrieve ten?
    Thankss

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: more then one record

    Do you mean ten records (read fires ten times) of ten fields from one record (read fires once).

    vb.net Code:
    1. If objReader.HasRows Then
    2.      While objReader.Read
    3.          Label11.Text = (objReader.GetString(1))
    4.          Label12.Text = (objReader.GetString(2))
    5.          Label13.Text = (objReader.GetString(3))
    6. .....
    7.      End While
    8. End If
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    110

    Re: more then one record

    No No sorry if i wasnt clear i ment i have ten diffrent reecord in one table where bb in 98. I want all ten record deisplayed in ten diffrent label boxes.

    By changing objreader.getsting(1)) to objreader.getsting(2)), it retrives the same record but instead of getting the first field it gets the secound field. I do not want that i want the other ten records. Thanks

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: more then one record

    Try like this:

    vb.net Code:
    1. Dim x as Integer = 11
    2. Dim obj as Window.Forms.Lable
    3. Dim strLName as String = String.Empty
    4. If objReader.HasRows Then
    5.      While objReader.Read
    6.            strLName = "Lable" & x.ToString()
    7.            obj = strName
    8.            directcast(obj,Windows.Forms.Lable).Text = (objReader.GetString(1))
    9.      End While
    10. End If
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    110

    Re: more then one record

    Sorry Gary could you explain to how this work? So that i understand it and not just copy it. Thanks

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    110

    Re: more then one record

    Also where u have written
    obj = strName
    what does strName represent?

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: more then one record

    You need to increment the the lable name. This can be done in various ways. You can have a counter and code the counter to increment and use that number to decide which hard coded label you need to write to. Or you use the contatinated string (Lable + incremtent) to generate a name use the name to set the object on the form to that label and a directcast to set the object to a label and place the text there
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

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



Click Here to Expand Forum to Full Width