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:
Dim objConn As ADODB.Connection = New ADODB.Connection()
Dim objRs As ADODB.Recordset = New ADODB.Recordset()
Dim i As Integer
objConn.ConnectionString = "Provider=SQLOLEDB;data Source=CC200392-B; Initial Catalog=MB;User Id=sa;Password=***;"
objConn.Open()
objRs.Open("Select * from Users", objConn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
For i = 0 To objRs.Fields.Count - 1
ListBox1.Items.Add(objRs.Fields(i))
Next
objRs.Close()
objRs = Nothing
objConn.Close()
objConn = Nothing
Re: uh? error adding SQL db fields to listbox
Quote:
VB Code:
For i = 0 To objRs.Fields.Count - 1
ListBox1.Items.Add(objRs.Fields(i))
Next
objRs.Close()
objRs = Nothing
objConn.Close()
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.