查询表达式中的{"语法错误(缺少运算符)'PlanName =一次30天'。“} [英] {"Syntax error (missing operator) in query expression 'PlanName =One Time 30 Days'."}
本文介绍了查询表达式中的{"语法错误(缺少运算符)'PlanName =一次30天'。“}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
con.Open();
int amt = int .Parse(textBox7_SetAmount.Text);
string plan = comboBox1_ChoosePlan.Text;
string st = 更新Mess_Plans设置Amount = + amt + 其中PlanName = +计划;
OleDbCommand cmd = new OleDbCommand(st,con);
int temp = cmd.ExecuteNonQuery();
解决方案
你错过了撇号。但更好的想法是使用参数化语句。
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);
我也希望您不要将数据访问代码直接放在UI中代码。
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();
解决方案
You're missing the apostrophes. But a better idea is to use a parameterized statement.
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.
这篇关于查询表达式中的{"语法错误(缺少运算符)'PlanName =一次30天'。“}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文