Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55343

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need help: VB.net vs Access database Posted by robrechtleus on 29 May 2012 at 10:25 AM
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.

 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()
                da.Fill(ds, "SELECT * FROM tblKlanten")
                da.Dispose()
                cnn.Close()

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


This is the code behind the button:
 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


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.


 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

the weird thing wit the substring above is my inventive way to make the proper command :)
 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)


        rd = cmd.ExecuteReader(CommandBehavior.CloseConnection)

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


Many thanks in advance.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.