Answered by:
wrong near where clause

Question
-
User-1101529841 posted
Hi,
I am doing insert with where clause, i have error near the where clause.
protected void btnSave_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=MZC-RWAHDAN\\MYPROJECT2015;Initial Catalog=Testing_database;Persist Security Info=True;User ID=sa;Password=??;"); SqlCommand command1 = new SqlCommand("INSERT INTO New_Requests(subtotalmaterial,subtotallabour,subtotalgeneral,subtotalothers,grandtotal,per_overhead,total_overhead,per_profit,total_profit,thesellingprice,per_comm,total_comm,total_min_sell,total_min_quot) Values (@par1,@par2,@par3,@par4,@par5,@par6,@par7,@par8,@par9,@par10,@par11,@par12,@par13,@par14) where BOQ_REF_NO = '" + DropDownList4.SelectedItem.Text.ToString() + "'", con); con.Open(); command1.Parameters.Add(new SqlParameter("@par1", SomeGlobalVariables.thesubtotal_materials.ToString())); command1.Parameters.Add(new SqlParameter("@par2", SomeGlobalVariables.thesubtotal_LABOUR.ToString())); command1.Parameters.Add(new SqlParameter("@par3", SomeGlobalVariables.thesubtotal_GENERAL.ToString())); command1.Parameters.Add(new SqlParameter("@par4", SomeGlobalVariables.thesubtotal_OTHERS.ToString())); command1.Parameters.Add(new SqlParameter("@par5", SomeGlobalVariables.thegrandtotal.ToString())); command1.Parameters.Add(new SqlParameter("@par6", SomeGlobalVariables.theperoverhead.ToString())); command1.Parameters.Add(new SqlParameter("@par7", SomeGlobalVariables.thetotaloverhead.ToString())); command1.Parameters.Add(new SqlParameter("@par8", SomeGlobalVariables.theperprofit.ToString())); command1.Parameters.Add(new SqlParameter("@par9", SomeGlobalVariables.thetotalprofit.ToString())); command1.Parameters.Add(new SqlParameter("@par10", SomeGlobalVariables.thesellingprice.ToString())); command1.Parameters.Add(new SqlParameter("@par11", SomeGlobalVariables.thepercomm.ToString())); command1.Parameters.Add(new SqlParameter("@par12", SomeGlobalVariables.thetotalcomm.ToString())); command1.Parameters.Add(new SqlParameter("@par13", SomeGlobalVariables.thetotalminsell.ToString())); command1.Parameters.Add(new SqlParameter("@par14", SomeGlobalVariables.thetotalminquote.ToString())); command1.ExecuteNonQuery(); lblmsg.Visible = true; lblmsg.Text = "The Request has been sent to controller for comments"; lblmsg.ForeColor = System.Drawing.Color.Green; }
can someone help please.
Thanks.
Thursday, February 4, 2016 5:29 PM
Answers
-
User1124521738 posted
the where clause is invalid for an insert/value action. if you were doing an insert/select you could have a where clause.
you probably need an if (somevariable == DropDownList4.SelectedItem.Text) { ...... } clause around your insert statement so the insert only fires some of the time.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 4, 2016 5:35 PM
All replies
-
User1124521738 posted
the where clause is invalid for an insert/value action. if you were doing an insert/select you could have a where clause.
you probably need an if (somevariable == DropDownList4.SelectedItem.Text) { ...... } clause around your insert statement so the insert only fires some of the time.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 4, 2016 5:35 PM -
User-1101529841 posted
i don't know what i was thinking...doh...i need an update not insert.
Thanks.
Thursday, February 4, 2016 5:42 PM