Reputation: 1
I receive “Syntax Error in FROM clause”
Any help/ideas are greatly appreciated, I’m a beginner if you can’t tell!
CODE is as follows:
Private Sub cmdDelete_click()
Dim sql As String, rCount As Integer
If me.dirty then
Me.dirty = False
End if
Set dbs = currentdb
SQL = “DELETE Item FROM item = ‘“ & me.txtItem & “‘“ & “WHERE ID=“ & me.txtID2
Dbs.Execute sql, dbFailOnError
rCount = dbs.RecordsAffected
If rCount >0 then
Msgbox “The item List has been updated”
List40.Requery
Clear
End if
End sub
Upvotes: 0
Views: 91
Reputation: 320
You can simply use DELETE in SQL like this.
DELETE FROM Item WHERE ID='" + txtID2.Text + "'
Where you can delete an item base on the items ID.
Upvotes: 1
Reputation: 19767
FROM
must refer to a table (whether a physical table you've built, a stored query, or the result of an embedded SQL string).
FROM item = ‘“ & me.txtItem & “‘“
in your code has no meaning to SQL.
This avoids the string concatenation to build up your SQL - just pass the value as a parameter and then execute the query:
Private Sub cmdDelete_Click()
Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.CreateQueryDef("", _
"PARAMETERS Identifier TEXT (255); " & _
"DELETE * FROM Table1 WHERE ID = Identifier")
With qdf
.Parameters("Identifier") = Me.txtID2
.Execute
End With
End Sub
Upvotes: 1
Reputation: 129
I have Read your Question the Error in the Your SQL QUERY Try This:
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText ="DELETE FROM Item WHERE ID='"+txtyoutextbox.Text.Trim()+"';
cmd.ExecuteNonQuery();
Upvotes: 0