标准表达式中的数据类型不匹配,即使代码完美,错误仍然存在
本文关键字:完美 代码 错误 存在 表达式 数据类型 不匹配 标准 | 更新日期: 2023-09-27 18:15:21
这是我更新我的表doctorss的代码。代码没有错误,我已经确保表数据类型是ok的;Doctor_ID
数据类型设置为自动编号,其他数据类型设置为短文本。
进一步,我知道这段代码将对sql注入有影响,我应该使用参数来做到这一点,但由于这种方式是可能的,并且有一个我无法解决的错误,我需要知道我在更新表时得到的错误的解决方案。
错误:条件表达式中数据类型不匹配
我正在使用Access 2013和Visual studio 2013。
private void button6_Click(object sender, EventArgs e)
{
try
{
OleDbConnection cone = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:''dev''assignt_soft''healthline_''healthline_''healthline_db.accdb");
OleDbCommand come = new OleDbCommand("UPDATE doctorss set Doctor_Name='"+textBox3.Text+"', dspecial='"+comboBox4.Text+"', dday= '"+comboBox3.Text+"', dtime= '"+textBox2.Text+"' where Doctor_ID='" + textBox4.Text+"';");
come.Connection = cone;
cone.Open();
come.ExecuteNonQuery();
cone.Close();
MessageBox.Show("Doctor updated");
OleDbConnection cont = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:''dev''assignt_soft''healthline_''healthline_''healthline_db.accdb");
OleDbCommand comt = new OleDbCommand("select * from doctorss", cont);
DataTable dte = new DataTable();
cont.Open();
dte.Load(comt.ExecuteReader());
dataGridView1.DataSource = dte;
cont.Close();
return;
}
catch (OleDbException expee)
{ MessageBox.Show(expee.Message); }
}
我已经确保表的数据类型是ok的
因为Doctor_ID
是自动编号,你不应该使用引号
OleDbCommand come = new OleDbCommand("UPDATE doctorss set
Doctor_Name='"+textBox3.Text+"',
dspecial='"+comboBox4.Text+"',
dday= '"+comboBox3.Text+"',
dtime= '"+textBox2.Text+"'
where Doctor_ID=" + textBox4.Text+";");