Gegevenstypen komen niet overeen in criteriumexpressie.( in VB.net)

Status
Niet open voor verdere reacties.

yves72

Nieuwe gebruiker
Lid geworden
28 apr 2013
Berichten
1
Hallo,

Ik moet voor mijn eindwerk een website maken en zit nu vast bij het volgende probleem.

Ik wil een select cmd naar mijn database doen en krijg de volgende fout:
"Gegevenstypen komen niet overeen in criteriumexpressie."

Dit is het deel van de code waar het misloopt:

Code:
'controleert of product al in winkelmand zat
        strWinkelmandCMD = "select id from tblWinkelmandLijnen where ( WinkelmandID='" & intWinkelmandID & "' and productID ='" & intProductID & "')"
        scmdWinkelmand.Connection = cnnDatabase
        scmdWinkelmand.CommandText = strWinkelmandCMD
        cnnDatabase.Open()

        If scmdWinkelmand.ExecuteScalar.ToString = "" Then
        ...

Dit is heel mijn code voor als de fout missschien toch hier aan ligt:
Code:
 Protected Sub btnWinkelmandToevoegen_Click(sender As Object, e As System.EventArgs) Handles btnWinkelmandToevoegen.Click
        'comands worden gedeclareerd
        Dim scmdWinkelmand As New OleDb.OleDbCommand
        'comandstring
        Dim strWinkelmandCMD As String
        'declarering van strings die opgezochte ID's en namen bijhouden
        Dim strGebruiker, strProductID, strWinkelmandID, strAantal As String
        Dim intProductID, intWinkelmandID, intID As Integer
        'gebruikernaam word opgehaald
        strGebruiker = Session("gebruiker")

        'connectionstring wordt opgevraagd
        Dim cnnDatabase As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("GIPData").ConnectionString)
        Dim label As Label

        'productID wordt opgehaald
        label = dtlProduct.Items(0).FindControl("lblProductID")
        strProductID = label.Text

        'winkelmandID wordt opgevraagd van de gebruiker en word in string gestoken
        strWinkelmandCMD = "select WinkelmandID from tblWinkelmand where ( gnaam='" & strGebruiker & "')"
        scmdWinkelmand.Connection = cnnDatabase
        scmdWinkelmand.CommandText = strWinkelmandCMD
        cnnDatabase.Open()
        strWinkelmandID = scmdWinkelmand.ExecuteScalar.ToString
        cnnDatabase.Close()
        intWinkelmandID = strWinkelmandID
        intProductID = strProductID
        Dim dblWinkelmandID As Double = intWinkelmandID
        Dim dblProductID As Double = intProductID

        'controleert of product al in winkelmand zat
        strWinkelmandCMD = "select id from tblWinkelmandLijnen where ( WinkelmandID='" & intWinkelmandID & "' and productID ='" & intProductID & "')"
        scmdWinkelmand.Connection = cnnDatabase
        scmdWinkelmand.CommandText = strWinkelmandCMD
        cnnDatabase.Open()

        If scmdWinkelmand.ExecuteScalar.ToString = "" Then
            intID = scmdWinkelmand.ExecuteScalar
            strWinkelmandCMD = "INSERT INTO tblWinkelmandLijnen(WinkelmandID, productID, aantal) VALUES ('" & intWinkelmandID & "','" & intProductID & "', '1')"
            dtsWinkelmandToev.InsertCommand = strWinkelmandCMD
            dtsWinkelmandToev.Insert()

        Else
            strAantal = scmdWinkelmand.ExecuteScalar
            strWinkelmandCMD = "UPDATE tblWinkelmandLijnen(WinkelmandID, productID, aantal) VALUES ('" & intWinkelmandID & "','" & intProductID & "', '1')"
            dtsWinkelmandToev.InsertCommand = strWinkelmandCMD
            dtsWinkelmandToev.Insert()
            strWinkelmandCMD = "UPDATE tblWinkelmandLijnen SET aantal = '" & strAantal & "' WHERE id = '" & intID & "'"

        End If
        cnnDatabase.Close()

    End Sub

Dit is de opstelling van mijn database:

Code:
tblWinkelmand:
WinkelmandID(Autonumeriek), gebruikerID(numeriek), gnaam(tekst)

tblWinkelmandLijnen:
Id(autonumeriek), WinkelmandID(numeriek), productID(numeriek), aantal(numeriek)

Alvast bedankt,

mvg,

Yves
 
Laatst bewerkt door een moderator:
Je ID's zijn numeriek, maar je vergelijkt ze echter als tekst:
WinkelmandID='" & intWinkelmandID & "' and productID ='" & intProductID & "')" levert
WinkelmandID='1' and etc.
Zonder de quotes gaat het wel go
WinkelmandID=" & intWinkelmandID & " and productID =" & intProductID & ")"
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan