关于Access数据库id自增列用update语句报“标准表达式中数据类型不匹配”的问题

来源:互联网 发布:ubuntu 双系统安装 编辑:程序博客网 时间:2024/05/18 01:53

Accesss数据库表fee存在自增列ID.

原语句1:

string str="update fee set 项目='" + textBox1.Text.Trim() + "',费用='" + textBox2.Text.Trim() + "',收入支出='" + cbb1.Text + "' where ID='"+dataGridView1.CurrentRow.Cells[0].Value.ToString()+"' ";

结果:

失败,标准表达式中数据类型不匹配

 

原语句2: 考虑到该自增列是长整形,打算转化为int32

string str="update fee set 项目='" + textBox1.Text.Trim() + "',费用='" + textBox2.Text.Trim() + "',收入支出='" + cbb1.Text + "' where ID='"+Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString())+"' ";

结果:

失败,标准表达式中数据类型不匹配

 

原语句3: 解决办法,分语句

string str="update fee set 项目='" + textBox1.Text.Trim() + "',费用='" + textBox2.Text.Trim() + "',收入支出='" + cbb1.Text + "' where ID=";

str=str +dataGridView1.CurrentRow.Cells[0].Value.ToString();

相当于把原语句1分拆了,Access真0疼。

结果:

成功

 

 

原创粉丝点击