I get an error when I input the drop down list parameter as data, I could not add the parameter data into the invoice table,the parameter data for subtotal, tax and total got their own value, but it only work well for manually input the data.
Drop down list parameter:
using (var cmd = con.CreateCommand())
{
cmd.CommandText = @"insert into Invoice(subtotal,tax,total) values (@subtotal,@tax,@total); select SCOPE_IDENTITY() as invoiceID;";
cmd.Parameters.AddWithValue("@subtotal", subtotal);
cmd.Parameters.AddWithValue("@tax", tax);
cmd.Parameters.AddWithValue("@total", total);
object OBJinvoiceID = cmd.ExecuteScalar();
}
Manually input:
using (var cmd = con.CreateCommand())
{
cmd.CommandText = @"insert into Invoice(subtotal,tax,total) values (2,2,2); select SCOPE_IDENTITY() as invoiceID;";
object OBJinvoiceID = cmd.ExecuteScalar();
}
Just remove the field from your values-listing:
insert into Invoice(subtotal,tax,total) values (@subtotal,@tax,@total); select SCOPE_IDENTITY() as invoiceID;
Also you can use the OUTPUT-Clause to get the value using:
into Invoice(subtotal,tax,total) OUTPUT invoiceID values (@subtotal,@tax,@total);
In the case you actually want to set the identity
-column manually, you can use SET IDENTITY_INSERT
as described here in MSDN