Need help: VB.net vs Access database

Hello, I need some help with my program for school.
Even my teacher can't fix it so I ask it here.
ooh and sorry for the language it's in Dutch...

First of all, when I click the button "show" (Tonen) after starting up the program fails. with this error (code line is in red):
Fill: SelectCommand.Connection property has not been initialized.

But when I do something else first it will actually work.

[code] Sub subMaakConnectie(ByVal strSQL As String)
'********************************
'* Maak connectie en vul dataset.
'********************************
' Zoek pad naar database
Dim strDBPad As String = fntPath()
Dim da As New OleDbDataAdapter(strSQL, cnn)
Dim ds As New DataSet()

subOpenConnection()

If strSQL = "" Then
MessageBox.Show("Selecteer eerste een criteria om te zoeken", "ERROR")
Else
If TabControl1.SelectedTab Is tcKlanten Then
subOpenConnection()
[color=Red] da.Fill(ds, "SELECT * FROM tblKlanten")[/color]
da.Dispose()
cnn.Close()

' ... en vul datagrid
With dgKlanten
.AutoGenerateColumns = True
.DataSource = ds
.DataMember = "SELECT * FROM tblKlanten"
End With...........[/code]

This is the code behind the button:
[code] Private Sub btnKlantTonen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKlantTonen.Click
Dim strSQL As String = ""
strSQL = "SELECT * FROM tblKlanten ORDER BY fldKlantNaam"
subMaakConnectie(strSQL)
End Sub[/code]

The second problem has something to do with making a combobox that uses the value of another combobox to make the SQL line.
Making the line is done, and for what i can see it should work but is doesn't.
This error occures at he red marked line:
No value given for one or more required parameters.


[code] Private Sub cmbBestelProduct_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBestelProduct.SelectedIndexChanged
Dim strCommand As String
Dim strField As String
strCbSelect = "KlantVoornaam"
strCommand = "'SELECT DISTINCT fldProductPrijs FROM tblProducten WHERE fldproductNaam=" & CStr(cmbBestelProduct.SelectedItem) & "'"
'MessageBox.Show(strCommand)
strCommand = strCommand.Substring(1, (strCommand.Length - 2))
'MessageBox.Show(strCommand)
strField = "fldProductenPrijs"
fntZoeken(strCommand, strField)
End Sub[/code]
the weird thing wit the substring above is my inventive way to make the proper command :)
[code] Function fntZoeken(ByVal strCommand As String, ByVal strField As String)
subOpenConnection()

' 2. Maak het commando
Dim cmd As OleDbCommand
Dim strCmd As String = strCommand

cmd = New OleDbCommand(strCmd, cnn)

' 3. Haal gegevens op
Dim res As New List(Of String)
Dim strItem As String
Dim rd As OleDbDataReader
'MessageBox.Show(strCmd)
'MessageBox.Show(strField)


[color=Red] rd = cmd.ExecuteReader(CommandBehavior.CloseConnection)[/color]

If rd.HasRows Then
Do While rd.Read
strItem = CStr(rd(strField))
res.Add(strItem)
cmbBestelKlantVoornaam.Items.Add(strItem)
Loop
End If
cmbBestelKlantVoornaam.DroppedDown = True
[/code]

Many thanks in advance.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories