Click here to Skip to main content
15,881,612 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
con.Open();
int amt=int.Parse(textBox7_SetAmount.Text);
string plan=comboBox1_ChoosePlan.Text;


string st = "update Mess_Plans set  Amount=" + amt + " where PlanName =" + plan;
OleDbCommand cmd = new OleDbCommand(st, con);
int temp = cmd.ExecuteNonQuery();
Posted

1 solution

You're missing the apostrophes. But a better idea is to use a parameterized statement.

C#
string st = "update Mess_Plans set  Amount=@amt where PlanName=@plan";
                OleDbCommand cmd = new OleDbCommand(st, con);
cmd.Parameters.AddWithValue ( "@amt" , amt ) ;
cmd.Parameters.AddWithValue ( "@plan" , plan ) ;




I also hope you are not putting your Data Access Code directly in your UI code.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900