private void save_Click(object sender, EventArgs e)
{
ACCOUNT.oo.Open();
string QRY = "insert into size(SIZENO,SIZE,COVERAGE,WEIGHT)
values('" + size_id.Text + "','" +txt_size.Text + "','" +txt_coverage.Text
+ "','" +txt_weight.Text + "')";
OleDbCommand ODB = new OleDbCommand(QRY,ACCOUNT.oo);
ODB.ExecuteNonQuery();
MessageBox.Show("Inserted Sucessfully..");
ACCOUNT.oo.Close();
}
答案 0 :(得分:6)
您的数据库列看起来像是用于数字数据,并且引用了您要插入的值。删除单引号将解决这个问题。
您还应该参数化您的查询,例如:
private void save_Click(object sender, EventArgs e)
{
ACCOUNT.oo.Open();
string QRY = "insert into size(SIZENO,SIZE,COVERAGE,WEIGHT) values(?,?,?,?)";
using(OleDbCommand ODB = new OleDbCommand(QRY, ACCOUNT.oo))
{
// change the OleDbType based on your actual data types
ODB.Parameters.Add("SIZENO", OleDbType.Integer).Value = int.Parse(size_id.Text);
ODB.Parameters.Add("SIZE", OleDbType.Integer).Value = int.Parse(txt_size.Text);
ODB.Parameters.Add("COVERAGE", OleDbType.Integer).Value = int.Parse(txt_coverage.Text);
ODB.Parameters.Add("WEIGHT", OleDbType.Integer).Value = int.Parse(txt_weight.Text);
ODB.ExecuteNonQuery();
}
MessageBox.Show("Inserted Sucessfully..");
ACCOUNT.oo.Close();
}