Saturday, February 25, 2012

Please Help: Error: Missing semicolon (;) at end of SQL statement.

Hey

I am trying to retieve a value from teh database and add one to it, then update the database with thenew value before redirecting to a page.

I am recieving this error and don't know why, i have the following coed below.


Dim objReaderQ as OleDBDataReader

Dim strSQLRead As String
Dim objCmd As New OleDbCommand

strSQLRead ="Select Quantity from tblCart Where (Productid=" & intProdidHold & ") AND (Cartid='" & strCartid & "')"

objCmd = new OleDbCommand(strSQLRead, objConn)
objReaderQ = objCmd.ExecuteReader()

if objReaderQ.Read()
'update quantity by 1

Dim i as integer
i = objReaderQ("quantity")
i = i + 1

objReaderQ.Close()

Dim strSQLQuantity as String = "INSERT INTO tblCart (Quantity) VALUES (@.quantity) WHERE (productid=" & intProdidHold & ") AND (Cartid='" & strCartid & "');"

Dim objCmdQuantity As New OleDbCommand(strSQLQuantity, objConn)

objCmdQuantity.Connection = objConn

objCmdQuantity.Parameters.Add("@.quantity", OleDbType.VarChar, 255)
objCmdQuantity.Parameters("@.quantity").Value = i

objCmdQuantity.ExecuteNonQuery() ' <-- Error Is Occuring On This Line

Response.Redirect("ViewBasket.aspx")

end if

I really can't see what is wrong as i have placed the semi colon it wanted at the end of the string.

Thanks you for your time

ChrisHey,

I have solved this problem, wrong sql statement, should be update! lol :(

But i do have the problem that once go to the viewbasket.aspx page it shows the product with the quantity 1, as it pulls the quantity from the db and its default value is 1 (which is correct).

But now if that same product is clicked 'Add To basket' for a second time, it executes the above code and goes to the viewbasket.aspx page, but the quantity stays as 1 ! (should be 2)

And now if that same product is clicked 'Add To basket' for a third time, it executes the above code again and goes to the viewbasket.aspx page, but this time the quantity is 2 ! (should be 3)

From this point on the code worked fine and increments the number properly, 4,5,6 etc..

Any idea why the first two clicks dont work ?

Thank you for your help

Chris

No comments:

Post a Comment