guys plss help me with this need urgent why i cannot delete row in database

this my code

Try
            Dim dsql As String
            Dim connect As New OleDbConnection(conString)
            connect.Open()

            dsql = "DELETE "
            dsql = dsql & "FROM InventoryItem "
            dsql = dsql & "WHERE TransactionDate = '" & TransactionDateText.Value & "' AND "
            dsql = dsql & "ItemName = '" & ItemNameText.Text & "' AND Quantity = '" & QuantityText.Text & "' AND "
            dsql = dsql & "Price = '" & PriceText.Text & "' AND Cost = '" & CostText.Text & "' AND "
            dsql = dsql & "Type = '" & InTextbox.Text & "'"
            MessageBox.Show(dsql)
            Dim command As New OleDbCommand(dsql, connect)
            Dim n As Integer = 0
            n = command.ExecuteNonQuery
            If n <> 0 Then
                MsgBox("Transaction Deleted", MsgBoxStyle.Information)
            Else
                MsgBox("Transaction Not Deleted", MsgBoxStyle.Information)
            End If


        Catch ex As Exception
            MsgBox("ERROR : " & ex.Message.ToString)
        End Try

i put that code in a button

when the user click a row in datagrid it will put the data to textbox and after that when the button click the above code will executed..
but i got an error "Data Type Mismatch In Criteria Expression" help me guys

Recommended Answers

All 4 Replies

help me guys

Normally quantity, price and cost are numeric, so you do not need to surround the values wit single cuootes.

IE: dsql = dsql & "Price = " & PriceText.Text & " AND Cost = " & CostText.Text & " AND "

Hope this helps

thanks for the reply lolafuerter

but it gives me the same problem

pls help me guys about this one really need to finish my work

The data type mismatch error means that some of the fileds in the where clause have distinct definition than the actually comparing value.

Try a slect with the same WHERE, and test, one by one, each field filter. You will find the offending one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.