数据类型不匹配,同时更新
问题描述:
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\PMEnterprise.accdb;Persist Security Info=True;Jet OLEDB:Database Password=???????");
try
{
string query;
conn.Open();
OleDbCommand cmdupdate = new OleDbCommand();
cmdupdate.Connection = conn;
query = "UPDATE Print_Cash_Entry_Credit SET Token_No = '" + txttoken.Text + "', Entry_Date = '" + dtpdate.Text + "', Sender_Name = '" + txtSender.Text + "', Center_Name = '" + txtcenter.Text + "', Money_Amount = '" + txtmoney.Text + "', Receiver_Name = '" + txtReceiver.Text + "', Mob_No = '" + txtmono.Text + "', PM_Amount_Com='0', Company_Amount_Com = '0' WHERE ID = '1'";
cmdupdate.CommandText = query;
cmdupdate.ExecuteNonQuery();
MessageBox.Show("Data Updated!");
conn.Close();
}
catch (Exception ex1)
{
MessageBox.Show(ex1.ToString());
}
这里截图的表结构..数据类型不匹配,同时更新
我收到“数据类型不匹配条件表达式中的”错误
答
ID是一个数字,但是你传递一个字符串('ID')。
试试这个:
... WHERE ID = 1"
答
只是第一件事,我看到你用''来分配一个DataType => Number。
就像Plutonix说的那样,确保研究如何构建查询,以便正确传递数据类型。
这可能是所有这些值作为字符串传递使用SQL参数...和做研究 - 这来了几次一个星期。 – Plutonix
由于您在表中使用Token_No的数字类型,并尝试通过查询传递文本(字符串类型),这种类型的小问题不应该在这里,请在编码时使用尽职调查,并将异常消息用作提示解决这个问题。 – ZabedAkbar