Results 1 to 6 of 6

Thread: [RESOLVED] Update of Production Record failed : Incorrect syntax near '('.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2007
    Posts
    134

    Resolved [RESOLVED] Update of Production Record failed : Incorrect syntax near '('.

    Hello,

    Could anyone please examine this code please and help with detecting the problem please???




    Code:
        Dim query As String = "Update PRODUCTION Set(VENDORID,TCAPONUMBER,DATEOUT,DATEREQUIRED,TOTALCOST,TOTALQUANTITY,APPROVEDBY,PREPAREDBY) VALUE(@VENDORID,@TCAPO ,@DATEOUT,@DATEREQUIRED,@TOTALCOST,@TOTALQUANTITY,@APPROVEDBY,@PREPAREDBY)WHERE PRODUCTIONID = @PRODUCTIONID"
    
            Dim Conn As SqlConnection = New SqlConnection(connectionString)
            Try
                Conn.Open()
                Dim command As SqlCommand = New SqlCommand(query, Conn)
                ' Add the parameters for the UpdateCommand.
                With command.Parameters
                    ' Add the parameters for the UpdateCommand. 
                    .Add(New SqlParameter("@TCAPO", SqlDbType.Int, 4)).Value = TCAPO
                    .Add(New SqlParameter("@DATEOUT", SqlDbType.DateTime, 8)).Value = DateOut
                    .Add(New SqlParameter("@DATEREQUIRED", SqlDbType.DateTime, 8)).Value = DateRequired
                    .Add(New SqlParameter("@TOTALCOST", SqlDbType.SmallMoney, 5)).Value = TotalCost
                    .Add(New SqlParameter("@TOTALQUANTITY", SqlDbType.Int, 4)).Value = TotalQuantity
                    .Add(New SqlParameter("@PREPAREDBY", SqlDbType.VarChar, 50)).Value = PreParedBy
                    .Add(New SqlParameter("@APPROVEDBY", SqlDbType.VarChar, 50)).Value = ApprovedBy
                    .Add(New SqlParameter("@VENDORID", SqlDbType.Int, 4)).Value = vendorID
                    .Add(New SqlParameter("@PRODUCTIONID", SqlDbType.Int, 4)).Value = ProductionID
                    '.Add(New SqlParameter("@TCAPO", SqlDbType.Int, 4)).Value = TCAPO
                End With
                command.ExecuteNonQuery()
            Catch e As Exception
                Throw New Exception("Update of Production Record failed : " & e.Message)
                Return False
            Finally
                'make sure the Connection is always closed
                Conn.Close()
            End Try
    Last edited by Reaction; May 20th, 2007 at 09:34 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Update of Production Record failed : Incorrect syntax near '('.

    It says that there's a syntax error.
    Code:
    "Update PRODUCTION Set(VENDORID,TCAPONUMBER,DATEOUT,DATEREQUIRED,TOTALCOST,TOTALQUANTITY,APPROVEDBY,PREPAREDBY) VALUE(@VENDORID,@TCAPO ,@DATEOUT,@DATEREQUIRED,@TOTALCOST,@TOTALQUANTITY,@APPROVEDBY,@PREPAREDBY)WHERE PRODUCTIONID = @PRODUCTIONID"
    "VALUE" is not an SQL key word. "VALUES" is.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2007
    Posts
    134

    Re: [2005] Update of Production Record failed : Incorrect syntax near '('.

    Thank you. Did you find another please? I still get the same error message when I run my code. I crosschecked the values . Is it ok to Save a Decimal to a SmallMoney Field In Database?

    Reaction

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Update of Production Record failed : Incorrect syntax near '('.

    Actually, I just realised that you're mongrelising UPDATE and INSERT syntax too. An UPDATE statement looks like this:
    Code:
    UPDATE MyTable SET Column1 = @Column1, Column2 = @Column2 WHERE ID = @ID
    while an INSERT statement looks like this:
    Code:
    INSERT INTO MyTable (Column1, Column2) VALUES (@Column1, @Column2)
    Also, don't you find it easier to read when the casing is consistent, with SQL key words in all upper case and object names in title case?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Update of Production Record failed : Incorrect syntax near '('.

    Also, this:
    vb.net Code:
    1. .Add(New SqlParameter("@TCAPO", SqlDbType.Int, 4)).Value = TCAPO
    is kinda long-winded when this:
    vb.net Code:
    1. .AddWithValue("@TCAPO", TCAPO)
    will do the same job.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2007
    Posts
    134

    Re: [2005] Update of Production Record failed : Incorrect syntax near '('.

    Thanks. That did the trick )

    Reaction

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width