我编写了使用 Microsoft Access 数据库插入和删除一些数据的代码,我可以插入数据,但是当我删除它时出现错误“data-type-mismatch-in-criteria-expression”我不知道为什么!有人帮我吗?
提前致谢 ;
private void Savebt_Click(object sender, EventArgs e)
{
//try
//{
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\me\Library Store\Library Store\Store.accdb");
try
{
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO Libarary ( ISBN, [Name], Gategory, Author, Cost, [Date]) " +
"VALUES ( @ISBN, @Name, @Gategory, @Author, @Cost, @Date) ";
cmd.Parameters.AddWithValue("@ISBN", ISBNTB.Text);
cmd.Parameters.AddWithValue("@Name", NameTB.Text);
cmd.Parameters.AddWithValue("@Gategory", GategoryTB.Text);
cmd.Parameters.AddWithValue("@Author", AuthorTB.Text);
cmd.Parameters.AddWithValue("@Cost", int.Parse(CostTB.Text));
cmd.Parameters.AddWithValue("@Date", dateTimePicker1.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Book Added!");
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void sellbt_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\me\Library Store\Library Store\Store.accdb");
try
{
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = " DELETE * FROM Libarary WHERE ISBN=@ISBN AND [Name]=@Name AND Gategory=@Gategory AND Author=@Author AND Cost=@Cost AND [Date]=@Date ";
cmd.Parameters.AddWithValue("@ISBN", ISBNTB.Text);
cmd.Parameters.AddWithValue("@Name", NameTB.Text);
cmd.Parameters.AddWithValue("@Gategory", GategoryTB.Text);
cmd.Parameters.AddWithValue("@Author", AuthorTB.Text);
cmd.Parameters.AddWithValue("@Cost", CostTB.Text);
cmd.Parameters.AddWithValue("@Date", dateTimePicker1.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Book removed to be sold!");
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
错误与我尝试删除的记录
数据库记录