I have been getting the above error and I can't figure it out but this is the code I tried:
What I have tried:
string constring = "Data Source=AnyStore.db;Version=3;New=True;Compress=True;";
SQLiteConnection con = new SQLiteConnection(constring);
SQLiteTransaction transaction = con.BeginTransaction();
try
{
con.Open();
foreach(DataGridViewRow row in dataGridView1.Rows)
{
using (SQLiteCommand com = new SQLiteCommand("insert into tbl_Details ([Date],[Serial_Number],[ItemId],[Item_Name],[Quantity],[Unitt_Price],[Total_Price],[Amount],[Cashier_Name]) values(@Date,@Serial_Number,@ItemId,@Item_Name,@Quantity,@Unitt_Price,@Total_Price,@Amount,@Cashier_Name)", con))
{
com.Parameters.AddWithValue("@Date", dtTrans.Text);
com.Parameters.AddWithValue("@Serial_Number", txtSerial.Text);
com.Parameters.AddWithValue("@Amount", txtTotalToPay.Text);
com.Parameters.AddWithValue("@ItemId", row.Cells["ItemId"].Value);
com.Parameters.AddWithValue("@Quantity", row.Cells["Quantity"].Value);
com.Parameters.AddWithValue("@Unitt_Price", row.Cells["Unit Price"].Value);
com.Parameters.AddWithValue("@Total_Price", row.Cells["Total Price"].Value);
com.Parameters.AddWithValue("@Amount", txtTotalToPay.Text);
com.Parameters.AddWithValue("@Cashier_Name", txtCashier.Text);
com.Transaction = transaction;
com.ExecuteNonQuery();
}
}
transaction.Commit();
con.Close();
}
catch(Exception ex)
{
transaction.Rollback();
con.Close();
MessageBox.Show(ex.Message);
}