Question ComboBox and Access

Jomathr

New member
Joined
Oct 3, 2011
Messages
1
Programming Experience
1-3
Hello again, I ran in a problem trying to populate my combobox from access
, I decided to use a function in a separate module to connect, querry and return the result to my combobox for the sake of diminishing the number of lines, but I can't get it to work in .net, I spent most of the weekend trying to solve this but again ran out of ideas

Here is the module I modified from what I found on the net:
VB.NET:
[COLOR=#000000][FONT=monospace]Module DataModule[/FONT][/COLOR]
    Dim cnn As Data.OleDb.OleDbConnection = Nothing    Dim DBpath As String = My.Settings.SDBPATH    Dim SQLString As String    Private cnnOpen As Boolean = False    Private Sub OpenConnection()        Dim strCNN As String = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBpath & ";Persist Security Info=True;Jet OLEDB:Database Password=Admin"""        Try            cnn = New Data.OleDb.OleDbConnection(strCNN)            cnn.Open()            cnnOpen = True        Catch ex As Exception            cnnOpen = False        End Try    End Sub    Sub CloseConnection()        If cnnOpen Then            cnn.Close()            cnn.Dispose()            cnnOpen = False        End If    End Sub    Public Function DBDataAcess(ByVal SQLString As String) As DataSet        If Not cnnOpen Then OpenConnection()        Dim daResult As Data.OleDb.OleDbDataAdapter = New Data.OleDb.OleDbDataAdapter(SQLString, cnn)        daResult.ContinueUpdateOnError = True        Dim dsReturn As DataSet = New DataSet        daResult.Fill(dsReturn)        Return dsReturn        dsReturn.Dispose()        daResult.Dispose()    End Function [COLOR=#000000][FONT=monospace]End Module[/FONT][/COLOR]

In the combobox section I try to acces it with the following code:
VB.NET:
[COLOR=#000000][FONT=monospace] Private Sub Form_Insc_Cour1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Form_Insc_Cour1.SelectedIndexChanged[/FONT][/COLOR]
        Dim i As Integer = 0        Dim SQLString As String = "Select * From Config_cours"        Dim dsReturn As DataSet = DataModule.DBDataAcess(SQLString)        Me.Form_Insc_Cour1.DataSource = DataModule.DBDataAcess(SQLString).Tables(0)        Me.Form_Insc_Cour1.DisplayMember = "Cours"        Me.Form_Insc_Cour1.ValueMember = "No"        While Not Me.Form_Insc_Cour1.DataSource            Form_Insc_Cour1.Items(i) = Me.Form_Insc_Cour1.DataSource            Me.Form_Insc_Cour1.DataSource.MoveNext()            i = i + 1        End While [COLOR=#000000][FONT=monospace]    End Sub[/FONT][/COLOR]

I remember .eof method for my "While Not" loop but I can't seem to make it work

Basically the table in my DB consist of 2 columns, the first being ID (autonumbers) and the second are the records I want to access via my combobox, there is about 10 rows for nom but it is subject to change.

Thank you again for your wondrous help and as always it is much appreciated.
 
It may just be me, but your code looks like it could do with a couple of carriage returns in there.
 

Latest posts

Back
Top