hello, I just need to fix this SQL statement, can comebody tell what's wrong. It is saying:
incorrect syntax near 'where'
str = "delete from service where serviceid = '" + serviceid + "'"
Printable View
hello, I just need to fix this SQL statement, can comebody tell what's wrong. It is saying:
incorrect syntax near 'where'
str = "delete from service where serviceid = '" + serviceid + "'"
Two things that are probably not the actual fault :
you should use "&" and not "+" for string concatenation
you should use parameters not string concatenation for passing in parameters
However neither are likely to cause that error. The most likely thing I can think of is that the field serviceid isn't a string and by placing it in single quotes you are treating it as one. I'd check the table design.
Moved To Database Development
What database are you using?
use parameters in queries: depending on ur db, use the appropriate command. ie for access use Oledbcommand rather than sqlcommand.
that said. Are you sure there is a value in the serviceid variable. maybe use & rather that + if you choose to keep your method.Code:Dim DeleteCommand As New SqlCommand("Delete from services where serviceid = @ServiceId", con)
DeleteCommand.Parameters.AddWithValue("@ServiceId", serviceid)
beaten to it. Keystone paul and I are thinking along the same lines;-)
I'll try to use parameter for serviceid, but it is a string and it gets a value.
ok, thanks, parameters helped. that works now
resolved
nightwalker your suggestion gives an error
$str = "delete from service where serviceid = $'ServiceId'"
character is not valid
oh no, I am still getting error
syntax error near serviceid
I rushed a bit :)