Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hey guys I'm really new to this but I need to populate my combo box's with an access data base as i am trying to make a cheap little checkout system and it doesnt seem to want to work.
If anyone could help me code my combo box and explain how it works would be amazing as I need to be able to individually select each one to be able to technically make a query to search for items and get a price from the db and being able to get change etc.

IF ANYONE COULD HELP THAT WOULD BE GREAT.
Posted
Comments
Sergey Alexandrovich Kryukov 26-Jul-14 22:30pm    
What have you tried so far?
—SA
Lachlan Bur 26-Jul-14 22:34pm    
Hey.
i've tried connecting them via databinding and it just does not want to work and I dont know the code for it. So im abit stuck.

1 solution

try this...

VB
    Public Sub FillCombo(ByVal combo As ComboBox, ByVal sSQL As String, ByVal sTable As String, ByVal sNum As Integer)
        Dim totalRow As Long = 0

        Dim da As New OleDb.OleDbDataAdapter(sSQL, con)
        Dim ds As New DataSet
        Dim i As Integer
dim totalRow as integer
        ds = New DataSet()
        da.Fill(ds, sTable)
        totalRow = ds.Tables(sTable).Rows.Count - 1
        combo.Items.Clear()
        For i = 0 To totalRow
            combo.Items.Add("" & ds.Tables(sTable).Rows(i).ItemArray.GetValue(0).ToString())
        Next
        If (combo.Items.Count > 0) Then combo.SelectedIndex = 0
        If sNum = 1 Then combo.Items.Add("ALL")
    End Sub 
 
Share this answer
 
Comments
Lachlan Bur 1-Aug-14 4:20am    
What do i declare con as?
and i get this error Error 2 Local variable 'totalRow' is already declared in the current block.
nilesh sawardekar 1-Aug-14 4:49am    
con is your connection
and remove dim totalrow as long=0 from code
Lachlan Bur 1-Aug-14 5:53am    
Yea mate it's not working at the moment or i am just too stupid to get it working.
nilesh sawardekar 1-Aug-14 6:47am    
where your getting stuck
Lachlan Bur 1-Aug-14 8:29am    
adding the connection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900