Please help me I got a error:Incorrect syntax near ')'. It pointed to the update_product.ExecuteNonQuery()

        Dim update_product As SqlCommand = New SqlCommand("Update sell Set Mode_Of_Payement(Cash)='" & TextBox9.Text & "',Payement='" & TextBox6.Text & "',Balance='" & TextBox8.Text & "', Mode_Of_Payement(Cheque)='" & TextBox9.Text & "',Cheque_No='" & TextBox4.Text & "' where Bill_No='" & txtbillno.Text & "'", myConnection)
        update_product.ExecuteNonQuery()
        update_product.Cancel()

Dani AI

Generated

The error "Incorrect syntax near ')'" usually means SQL saw a parentheses where it expected an identifier or operator. In this thread the primary culprits are the unusual column names and the way the SQL string is built. Column names that contain parentheses or other punctuation must be delimited (for SQL Server use square brackets) or, better, renamed to a safer identifier (for example ModeOfPaymentCash). Also confirm the data types: if Bill_No is numeric, do not surround it with single quotes — use a numeric parameter instead. was on the right track about the Bill_No type.

Use a parameterized UPDATE and properly delimit any weird column names. Parameterization fixes quoting problems and prevents SQL injection. Always open the connection, use a Using block for the command, set parameters with the correct SqlDbType (avoid blindly concatenating strings), and call ExecuteNonQuery() once. There is no need to call Cancel() after a synchronous ExecuteNonQuery(); dispose the command instead.

A few troubleshooting tips:

  • Paste the generated SQL into SQL Server Management Studio first to see the exact parser error.
  • If column names really contain parentheses, wrap them in brackets: [Mode_Of_Payement(Cash)].
  • Match parameter types to the column type (Int, Decimal, VarChar, etc.) and handle parse/Null conversions before assigning parameters.
  • If problems persist, simplify the UPDATE to one column and add columns back until the error reproduces.

For authoritative details on identifiers and the correct way to supply parameters see the SQL Server identifier rules and the ADO.NET SqlParameter documentation:
Database identifiers (SQL Server)
SqlParameter Class (ADO.NET)

In some fields that have parameter, are those the actual name of the field in your database? Bill_No is a number type so remove the single quotes.
Here's the sample query update.

Dim sql As String = "UPDATE sample SET one_one='" & txtone.Text & "', two_two='" & txttwo.Text & "', three_three='" & txtthree.Text & "', four_four='" & txtfour.Text & "', five_five='" & txtfive.Text & "' WHERE ID=" & _theID

thank you................
Can anybody explain me why this type of error coming

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.