I have a checedlist box - of which if the user checks a box and clicks the 'send' button a new row is created in the database (using the item checked)with the required information. But when I run it I keep on getting an error when I debug it saying ...
Syntax error in INSERT INTO statement
Can anyone help, I cant find the error
private void Send_Click(object sender, EventArgs e)
{
string err = "";
if (checkedListBox.Items.Count > 0)
{
for (int i = 0; i < checkedListBox.Items.Count; i++)
{
if (err == "")
{
err = checkedListBox.Items[i].ToString();
}
MAcon.Open();
OleDbCommand cmd = new OleDbCommand("Insert into Scrap([Order ID], Barcode, Notes, [Scrapped By], [Scrapped Date]) value(@OrderID, @Barcode, @Notes, @ScrappedBy, @ScrappedDate)", MAcon);
cmd.Parameters.AddWithValue("@OrderID", OrderID.Text);
cmd.Parameters.AddWithValue("@Notes", Note.Text);
cmd.Parameters.AddWithValue("@ScrappedBy", EmplID.Text);
cmd.Parameters.AddWithValue("@ScrappedDate", Date.Text);
cmd.Parameters.AddWithValue("@Barcode", err);
cmd.ExecuteNonQuery();
MAcon.Close();
}
}
}
What I have tried:
MAcon.Open();
OleDbCommand cmd = new OleDbCommand("Insert into Scrap([Order ID], Barcode, Notes, [Scrapped By], [Scrapped Date]) value(@OrderID, @Barcode, @Notes, @ScrappedBy, @ScrappedDate)", MAcon);
cmd.Parameters.AddWithValue("@OrderID", OrderID.Text);
cmd.Parameters.AddWithValue("@Notes", Note.Text);
cmd.Parameters.AddWithValue("@ScrappedBy", EmplID.Text);
cmd.Parameters.AddWithValue("@ScrappedDate", Date.Text);
cmd.Parameters.AddWithValue("@Barcode", err);
cmd.ExecuteNonQuery();
MAcon.Close();