none
Strange 'Incorrect Syntax' Error RRS feed

  • Question

  • Good evening everyone,

    I've found a really great Shopping Cart tutorial and everything is moving nicely up until this. The guy who wrote the tutorial used a Access Database and im using SQL Database instead the difference is minor however, in the Add Cart event im getting a really weird error everytime i hit the button to add something to my Tbl_Cart table in the database.

    The error reads this:

    Incorrect syntax near 's'.
    Unclosed quotation mark after the character string ', 1)'.


    My Add_Cart click event code:

    Sub Add_Cart(ByVal Src As Object, ByVal Args As EventArgs)

    Dim ISBN As Label = FormViewDisplay.FindControl("ISBN")

    Dim Book_Title As Label = FormViewDisplay.FindControl("Book_Title")

    Dim Book_Author As Label = FormViewDisplay.FindControl("Book_Author")

    Dim Book_Cost As Label = FormViewDisplay.FindControl("Book_Cost")

    'MsgBox(ISBN.Text & " " & Book_Title.Text & " " & Book_Author.Text & " " & Book_Cost.Text)

    Dim SQLConn As New SqlConnection(BookSource.ConnectionString)

    Dim SQLCommand As SqlCommand

    Dim SQLSyntax As String

    Dim SQLAddSyntax As String

    SQLConn.Open()

    SQLSyntax = "SELECT Count(*) FROM Tbl_Cart WHERE Order_ID = '" & Session("Order_ID") & "' AND ISBN = '" & ISBN.Text & "'"

    SqlCommand = New SqlCommand(SQLSyntax, SQLConn)

    If SqlCommand.ExecuteScalar() = 0 Then

    SQLAddSyntax = "INSERT INTO Tbl_Cart (Order_ID, Order_DT, ISBN, Book_Title, Book_Cost, Book_Qty) VALUES ('" & Session("Order_ID") & "', '" & Today & "', '" & ISBN.Text & "', '" & Book_Title.Text & "', '" & Book_Cost.Text & "', '1')"

    'MsgBox(SQLAddSyntax)

    SqlCommand = New SqlCommand(SQLAddSyntax, SQLConn)

    SqlCommand.ExecuteNonQuery()

    End If

    SQLConn.Close()

    Src.Text = "Item Added"

    Src.ForeColor = Color.FromName("#990000")

    Src.BackColor = Color.FromName("#E0E0E0")

    Src.Font.Bold = True

    End Sub





    If anything else you want me to post on here let me know. And thank you in advance for any help Smile

     

    EDIT: I figured out it was due to the Order_ID I had it Auto-Increment in the database i removed the Order_ID from the SQLAddSyntax and it finally inserted the stuff into the database.

     

    However, when i clicked on it again it re-added the same recorded into the table which is not supposed to be happening cause of the SQLSyntax statement i got that checks for duplicates.

    Monday, February 18, 2008 9:58 AM

Answers

  • Bleh managed to solve the issue god i hate when that happens you make a post and then minutes later its solved ^_^"

     

    It was fairly simple i removed Order_ID and Session("Order_ID") from the INSERT statement in the SQLAddSyntax.

     

    And in the SQLSyntax one i removed the WHERE Order_ID = '" & Session("Order_ID") & "'

     

    And that was it its now Inserting it into the database and if you click on the Item Added button it won't re-add the same item because it checks for duplicates.

     

     

    Sorry for any inconvenience i caused.

    Monday, February 18, 2008 10:41 AM