Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET SQL UPDATE STATEMENT 1

Status
Not open for further replies.

richfield

IS-IT--Management
Jan 6, 2005
23
GB
Hi,

I have the following error in my sql satatement:

Incorrect syntax near the keyword 'where',

my code is;

strSql=strSql.format("Update tblSales where SalesId={0} values('{1}','{2}','(3)')",ddlSalesID.selecteditem.value,txtSales.text,txtDate.text,txtEmployeeId.text)

Is there an obvious error?

Cheers Rich
 
Yes - you haven't told it which atble to update!

The syntax for an update statement should be:

Code:
UPDATE MYTABLE SET MYFIELD = 'A' WHERE MYCRITERIA = 'B'

It will also read the whole sql statement actually as a string so the statement passed to the db would actually by:

Code:
Update tblSales where SalesId={0} values('{1}','{2}','(3)')

If you need to add items to a string then you need to break out of the quotation marks.

Simple example:

Code:
strSQL = "UPDATE MYTABLE SET MYFIELD = '" & MyTextBox.Text & "' WHERE MYCRITERIA = '" & MyDropDownList.SelectedItem.Value & "'"

Hope this helps.


----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top