-
help deleting row
guys help me with this
i put the code into button
Code:
Dim connect As New OleDbConnection(conString)
connect.Open()
Dim dsql As String
dsql = "DELETE FROM InventoryItem"
dsql = dsql & "WHERE TransactionDate = '" & TransactionDateText.Text & "'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 & "'"
but when i click the button it gives me an error
the error is "Syntax Error in FROM clause"
help me guys sorry new in vs 2008
-
Re: help deleting row
This is a classic example of not looking at the data you're actually using. Don't just look at the code. Look at the data. Put this line after that code:
Code:
MessageBox.Show(dsql)
and the mistake should be obvious.
Also, why do this:
Code:
dsql = "DELETE FROM InventoryItem"
dsql = dsql & "WHERE TransactionDate = '" & TransactionDateText.Text & "'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 & "'"
when you can just do this:
Code:
dsql = "DELETE FROM InventoryItem" _
& "WHERE TransactionDate = '" & TransactionDateText.Text & "'AND " _
& " ItemName = '" & ItemNameText.Text & "' AND Quantity = '" & QuantityText.Text & "' AND" _
& " Price = '" & PriceText.Text & "' AND Cost = '" & CostText.Text & "' AND" _
& " Type = '" & InTextbox.Text & "'"
Further to that, don't use string concatenation to insert variables into SQL code at all. Follow the Blog link in my signature and check out my post on ADO.NET parameters.