我编写的每个代码都将一些数据插入 Microsoft Access 数据库,但我有一个错误“插入语句中的语法错误”我不知道为什么!有人帮我吗?提前致谢 ; 代码:
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("Data Added!");
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}