c#更新查询访问数据库 [英] c# update query access database
本文介绍了c#更新查询访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下查询更新名为customer的表
i am trying to update table called customer with follwing query
string Query = "UPDATE Customer SET Customer name=" + textBox2.Text +" WHERE Cnic=" + textBox9.Text;
da1 = new OleDbDataAdapter(Query,con);
dt1 = new DataTable();
da1.Fill(dt1);
biut我收到语法错误异常。请告诉我是什么问题。
da1.Fill(dt1);
biut i am getting syntax error exception.Kindly tell me what is the problem.
推荐答案
你必须逃脱你的字符串值:
You have to escape your string values:
string Query = "UPDATE Customer SET Customer name='" + textBox2.Text +"' WHERE Cnic='" + textBox9.Text + "'";
此外,更新语句不返回数据集,因此您需要使用OleDbCommand然后使用ExecuteScalar或ExecuteNonQuery来运行更新语句。
Also, update statements don't return a data set, so you need to use an OleDbCommand and then use the ExecuteScalar or ExecuteNonQuery to run the update statement.
这篇关于c#更新查询访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文