-
spaces causing problems in UPDATE sqlcommand
anyone have an idea as to why I'm getting errors that seem to be caused by spaces when I try to do an update command such as :
Dim myConnection As SqlConnection
myConnection = New SqlConnection("Data Source=SQL2KDB;Initial Catalog=OnlineJobs;Integrated Security=SSPI;")
Dim mycommand As SqlCommand
mycommand = New SqlCommand("UPDATE AvailableJobs SET Title = " & title & ", Supervisor = " & supervisor & " , Department = " & department & ", JobCode = " & jobCodeModified & ", Description = " & description & ", Requirements = " & requirements & ", PostedDate = " & postedDate & ",PostingEnds = " & postingEnds & ",ActiveOrPosted = " & activeOrPosted & " WHERE JobCode = " & jobcode, myConnection)
myConnection.Open()
mycommand.ExecuteNonQuery()
myConnection.Close()
it keeps saying there is a syntax error near ____ , the syntax error occurs wherever there is a space in the strings variables I'm sending in
Last edited by Matrix.net; 12-12-2006 at 11:08 AM.
-
String values must be enclosed in single quotes when using variable insertion in a SQL string. For example:
"UPDATE AvailableJobs SET Title = '" & title & "'"
You can avoid this issue using Command Parameters instead of variable insertion.
Paul
~~~~
Microsoft MVP (Visual Basic)
-
oh okay thanks , jeeez I always forget that
Similar Threads
-
By Tim Coulter in forum .NET
Replies: 1
Last Post: 09-20-2002, 10:25 AM
-
By Lewis Keim in forum VB Classic
Replies: 0
Last Post: 06-04-2002, 10:13 AM
-
By Alwin in forum Database
Replies: 0
Last Post: 05-07-2002, 08:34 PM
-
By John McLaughlin in forum Java
Replies: 1
Last Post: 10-22-2001, 11:23 AM
-
By Jared Doerr in forum VB Classic
Replies: 0
Last Post: 04-06-2000, 04:05 PM
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|