Results 1 to 4 of 4

Thread: uh? error adding SQL db fields to listbox

  1. #1

    Thread Starter
    Hyperactive Member phrozeman's Avatar
    Join Date
    Apr 2000
    Location
    Netherlands
    Posts
    442

    uh? error adding SQL db fields to listbox

    What is wrong with my code?
    The 'MB' database had 20 fields, but the only thing that will be added to the listbox is 20x 'ADODB.Internalfield'

    Please help me

    VB Code:
    1. Dim objConn As ADODB.Connection = New ADODB.Connection()
    2.         Dim objRs As ADODB.Recordset = New ADODB.Recordset()
    3.         Dim i As Integer
    4.         objConn.ConnectionString = "Provider=SQLOLEDB;data Source=CC200392-B; Initial Catalog=MB;User Id=sa;Password=***;"
    5.         objConn.Open()
    6.         objRs.Open("Select * from Users", objConn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
    7.         For i = 0 To objRs.Fields.Count - 1
    8.             ListBox1.Items.Add(objRs.Fields(i))
    9.         Next
    10.         objRs.Close()
    11.         objRs = Nothing
    12.         objConn.Close()
    13.         objConn = Nothing
    There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me

  2. #2

    Thread Starter
    Hyperactive Member phrozeman's Avatar
    Join Date
    Apr 2000
    Location
    Netherlands
    Posts
    442
    *bump*
    There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me

  3. #3
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262

    Re: uh? error adding SQL db fields to listbox

    VB Code:
    1. For i = 0 To objRs.Fields.Count - 1
    2.             ListBox1.Items.Add(objRs.Fields(i))
    3.         Next
    4.         objRs.Close()
    5.         objRs = Nothing
    6.         objConn.Close()
    7.         objConn = Nothing
    try ListBox1.Items.Add(objRs.Fields(i).name)

    also if you are just looking for the field names then change your sql to read "select top 1 from ....." rather than have it grabbing all records.

  4. #4

    Thread Starter
    Hyperactive Member phrozeman's Avatar
    Join Date
    Apr 2000
    Location
    Netherlands
    Posts
    442
    thanks, problem solved
    that was simple
    There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me

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