rai nalasa rai nalasa - 1 year ago 59
SQL Question

System.Data.SqlClient.SqlException on multiple WHERE query

I am using my quo_custname that is bind in my dropdownlist and use its value to
Insert my data.So whenever I choose a value on my dropdownlist quo_name change
but whenever I use my class for mysql Insertion.

I get this error

Additional information: Incorrect syntax near the keyword 'WHERE'.

Here is my code:

private void AddToQuotation()
cmd = new SqlCommand(@"INSERT INTO JobQuotations
WHERE quo_custname = '@customername'
AND quo_verified = 'no'",con);

string script = "alert(\"Functioning!\");";

ScriptManager.RegisterStartupScript(this, GetType(),
"ServerControlScript", script, true);

*Bonus question also how could I using try and catch so that it wouldn't break my program and get the SqlException name and the Additional information
in my script to popup a message.

Answer Source

Your statement doesn't make much sense to me. You are mixing insert into select syntax with insert into values syntax. Also, you are using quotes around your parameters, which won't work (they are interpreted as literals now).

Are you sure you didn't mean to update?

update JobQuotations
set    quo_disount     = @discount
,      quo_unitPrice   = @unitPrice
,      quo_TotalAmount = @totalAmount
,      quo_finishing   = @finishing
where  quo_custname    = @customername
and    quo_verified    = 'no'