我寫代碼插入和刪除一些數據與Microsoft Access數據庫,我可以插入數據,但當我刪除它我有一個錯誤「data-type-mismatch-in-criteria-expression」我不知道爲什麼!任何人幫助我?數據類型不匹配在條件表達式錯誤從MS Access中刪除與ADO.NET C#
在此先感謝;
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 [email protected] AND [Name][email protected] AND [email protected] AND [email protected] AND [email protected] AND [Date][email protected] ";
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());
}
} Errow與我嘗試刪除
數據庫記錄
它告訴我,該書被刪除待售!但我去數據庫的記錄仍然沒有刪除 –
@MohamedSafwat你告訴自己,書已售出。執行你的查詢只是意味着代碼被執行。如果仍未刪除,則表示您的查詢不是有效的查詢。雖然我強烈建議你做的所有處理的基礎上編號,而不是通過這麼多的領域 – Ehsan