Results 1 to 3 of 3

Thread: Fill combobox with field in table

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    31

    Fill combobox with field in table

    in VB6 we fill ComboBox Like This
    Code:
    Private Sub Form_Load()
    Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & App.Path & "\Inventory.mdb" & ";Persist Security Info=False"
    Adodc1.RecordSource = "select * from Transactions"
    Adodc1.Refresh
    Dim i As Integer
    For i = 1 To Adodc1.Recordset.RecordCount
    If Len(Adodc1.Recordset.Fields("InCountity")) <> 0 Then
    Combo1.AddItem (Adodc1.Recordset.Fields("ProductName"))
    
    End If
    
    Adodc1.Recordset.MoveNext
    Next
    End Sub
    how can we do this with VB.NET

  2. #2
    Lively Member
    Join Date
    Feb 2001
    Location
    KL Malaysia
    Posts
    64
    Code:
    Dim objConn as New OleDbConnection(strDSN)
    Dim objCmd as New OleDbCommand(strSQL, objConn)
    Dim objReader as OleDbDataReader = objCmd.ExecuteReader
    
    While objReader.Read
        If Not IsDBNull(objReader.GetValue(0)) Then
            Combo1.Add(objReader.GetString(1))
        End If
    End While
    I think...

    Of course you must know the ordinal number of your column to assign the parameters on GetValue and GetString
    Last edited by weijian; Apr 28th, 2002 at 08:31 PM.

  3. #3
    Thelonius
    Guest
    You need to put in

    Combo1.items.add(--your field text--)

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