C#でDataGridView
を使用してデータベースにデータを挿入しようとしています。次のエラーメッセージが表示され、私は、保存ボタンをクリックすると、しかし:Insertコマンドの問題
private void save_btn_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Stock.accdb");
con.Open();
for (int i = 0; i < dataGridView_insert.Rows.Count; i++)
{
OleDbCommand cmd = new OleDbCommand("INSERT INTO product(OV,Reference,Cod_Client,Client,Qtd,Type_product,Posicion_product,) VALUES ('" + dataGridView_insert.Rows[i].Cells["OV"].Value + "','" + dataGridView_insert.Rows[i].Cells["Reference"].Value + "','" + dataGridView_insert.Rows[i].Cells["Cod_Client"].Value + "','" + dataGridView_insert.Rows[i].Cells["Client"].Value + "','" + dataGridView_insert.Rows[i].Cells["Qtd"].Value + "','" + dataGridView_insert.Rows[i].Cells["Type_product"].Value + "','" + dataGridView_insert.Rows[i].Cells["Posicion_product"].Value + " ' ", con);
cmd.ExecuteNonQuery();
}
con.Close();
}
間違っているもの:
System.Data.OleDb.OleDbException was unhandled
HResult = -2147217900
Message = Syntax error in INSERT INTO statement.
Source = Microsoft Office Access Database Engine
ErrorCode = -2147217900
をここで私が持っているコードですか?
'Type_product、Posicion_product、)'この型を閉じるために投票します – fubo
文字列連結の代わりにパラメータを使用します。どの値が挿入されているのか分からない限り、何が間違っているのかを知ることは不可能です。さらに、SQLインジェクション攻撃の扉を開きます。 –
しかし、これがなくてもうまくいきません – satbr