I'm trying to insert a record from a DataGridView into a database, but I receive this error:
Parameterized Query '(@i1 int,@i2 varchar(50),@i3 varchar(50),@i4 varchar(50),@i5 var' expects parameter @i1, which was not supplied.
I have tested with a BreakPoint that c_id is not null, it does have a value.
*Note c_id is only a link to another table, it is not the invoice tables id.
string reference = "INV" + Random();
string status = "0";
SqlConnection cnn = new SqlConnection(connectionString);
string sqlInsert =
"INSERT INTO invoice(c_id, date_added, customer, status, items, description, quantity, unit_value, total, notes, notes_internal, ref, payment_ref) values(@i1,@i2,@i3,@i4,@i5,@i6,@i7,@i8,@i9,@i10,@i11,@i12,@i13)";
SqlParameter[] pInsert = new SqlParameter[13];
pInsert[0] = new SqlParameter("@i1", SqlDbType.Int, 5, customer_dd.SelectedValue.ToString());
pInsert[1] = new SqlParameter("@i2", SqlDbType.VarChar, 50, DateTime.Today.ToShortDateString());
pInsert[2] = new SqlParameter("@i3", SqlDbType.VarChar, 50, customer_dd.Text);
pInsert[3] = new SqlParameter("@i4", SqlDbType.VarChar, 50, status);
pInsert[4] = new SqlParameter("@i5", SqlDbType.VarChar, 50, "Item");
pInsert[5] = new SqlParameter("@i6", SqlDbType.VarChar, 50, "Descrioption");
pInsert[6] = new SqlParameter("@i7", SqlDbType.VarChar, 50, "Qty");
pInsert[7] = new SqlParameter("@i8", SqlDbType.VarChar, 50, "Unit_Value");
pInsert[8] = new SqlParameter("@i9", SqlDbType.VarChar, 50, "Line_Total");
pInsert[9] = new SqlParameter("@i10", SqlDbType.VarChar, 50, notes_txt.Text);
pInsert[10] = new SqlParameter("@i11", SqlDbType.VarChar, 50, internal_txt.Text);
pInsert[11] = new SqlParameter("@i12", SqlDbType.VarChar, 50, reference);
pInsert[12] = new SqlParameter("@i13", SqlDbType.VarChar, 50, null);
SqlCommand cmdInsert = new SqlCommand(sqlInsert,cnn);
cmdInsert.Parameters.AddRange(pInsert);
SqlDataAdapter da = new SqlDataAdapter();
da.InsertCommand = cmdInsert;
da.Update(ds, "invoice");
ds.AcceptChanges();