DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: spaces causing problems in UPDATE sqlcommand

  1. #1
    Join Date
    Aug 2006
    Location
    PA
    Posts
    259

    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.

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    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)

  3. #3
    Join Date
    Aug 2006
    Location
    PA
    Posts
    259
    oh okay thanks , jeeez I always forget that

Similar Threads

  1. OleDb Update problems with Jet 4.0
    By Tim Coulter in forum .NET
    Replies: 1
    Last Post: 09-20-2002, 10:25 AM
  2. Replies: 0
    Last Post: 06-04-2002, 10:13 AM
  3. Replies: 0
    Last Post: 05-07-2002, 08:34 PM
  4. JDBC Update Problems using PostgreSQL
    By John McLaughlin in forum Java
    Replies: 1
    Last Post: 10-22-2001, 11:23 AM
  5. Problems with my update in ado.
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center