0

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

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by lolafuertes
0

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

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.