|
-
Jul 16th, 2009, 06:05 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] sql delete statement
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 + "'"
-
Jul 16th, 2009, 06:10 AM
#2
Re: sql delete statement
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.
-
Jul 16th, 2009, 06:12 AM
#3
Re: sql delete statement
Moved To Database Development
What database are you using?
-
Jul 16th, 2009, 06:13 AM
#4
PowerPoster
Re: sql delete statement
use parameters in queries: depending on ur db, use the appropriate command. ie for access use Oledbcommand rather than sqlcommand.
Code:
Dim DeleteCommand As New SqlCommand("Delete from services where serviceid = @ServiceId", con)
DeleteCommand.Parameters.AddWithValue("@ServiceId", serviceid)
that said. Are you sure there is a value in the serviceid variable. maybe use & rather that + if you choose to keep your method.
beaten to it. Keystone paul and I are thinking along the same lines;-)
-
Jul 16th, 2009, 06:18 AM
#5
Re: sql delete statement
 Originally Posted by MrtforCode
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 + "'"
Try setting it out like:
$query = "delete * from service where serviceid = '$serviceid'";
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jul 16th, 2009, 06:19 AM
#6
Thread Starter
Fanatic Member
Re: sql delete statement
I'll try to use parameter for serviceid, but it is a string and it gets a value.
-
Jul 16th, 2009, 06:22 AM
#7
Thread Starter
Fanatic Member
Re: sql delete statement
ok, thanks, parameters helped. that works now
resolved
-
Jul 16th, 2009, 06:55 AM
#8
Thread Starter
Fanatic Member
Re: [RESOLVED] sql delete statement
nightwalker your suggestion gives an error
$str = "delete from service where serviceid = $'ServiceId'"
character is not valid
-
Jul 16th, 2009, 07:08 AM
#9
Thread Starter
Fanatic Member
Re: [RESOLVED] sql delete statement
oh no, I am still getting error
syntax error near serviceid
I rushed a bit
-
Jul 17th, 2009, 09:39 PM
#10
Re: [RESOLVED] sql delete statement
 Originally Posted by MrtforCode
nightwalker your suggestion gives an error
$str = "delete from service where serviceid = $'ServiceId'"
character is not valid
Oops, remove the "$" if ServiceId isn't a variable but the field name.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|