Hi all,
I am new to VB .net.
Iam trying to populate the database item into combo box.
Database Type:SQL(ODBC)
My code retuns no value in combo box
[CODE=vbnet]Public Class Form1
Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged
Dim Cmd As Odbc.OdbcComman d
Dim Con As Odbc.OdbcConnec tion
Dim Sql As String = Nothing
Dim Reader As Odbc.OdbcDataRe ader
Dim ComboRow As Integer = -1
Dim Columns As Integer = 0
Dim Category As String = Nothing
Dim Cmbbox As ComboBox
CmbboxMan.Items .Clear()
Con = New Odbc.OdbcConnec tion("Provider= Microsoft.Jet.O dbc.4.0;data source=" & Database & "")
Sql = "SELECT [Comp_ItemNumber] FROM [Components] ORDER BY [Comp_ItemNumber] Asc"
Cmd = New Odbc.OdbcComman d(Sql, Con)
Con.Open()
Reader = Cmd.ExecuteRead er()
While Reader.Read()
For Columns = 0 To Reader.FieldCou nt - 1
Category = Reader.Item(Col umns) 'READ COLUMN FROM DATABASE
Next
Cmbbox.Items.Ad d(Category)
ComboRow += 1
End While
Con.Close()
End Sub
End Class[/CODE]
Plz reply ASAP
I am new to VB .net.
Iam trying to populate the database item into combo box.
Database Type:SQL(ODBC)
My code retuns no value in combo box
[CODE=vbnet]Public Class Form1
Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged
Dim Cmd As Odbc.OdbcComman d
Dim Con As Odbc.OdbcConnec tion
Dim Sql As String = Nothing
Dim Reader As Odbc.OdbcDataRe ader
Dim ComboRow As Integer = -1
Dim Columns As Integer = 0
Dim Category As String = Nothing
Dim Cmbbox As ComboBox
CmbboxMan.Items .Clear()
Con = New Odbc.OdbcConnec tion("Provider= Microsoft.Jet.O dbc.4.0;data source=" & Database & "")
Sql = "SELECT [Comp_ItemNumber] FROM [Components] ORDER BY [Comp_ItemNumber] Asc"
Cmd = New Odbc.OdbcComman d(Sql, Con)
Con.Open()
Reader = Cmd.ExecuteRead er()
While Reader.Read()
For Columns = 0 To Reader.FieldCou nt - 1
Category = Reader.Item(Col umns) 'READ COLUMN FROM DATABASE
Next
Cmbbox.Items.Ad d(Category)
ComboRow += 1
End While
Con.Close()
End Sub
End Class[/CODE]
Plz reply ASAP
Comment