I have a datagridview filled from textboxes and comboboxes and I want from datagridview
to insert data into database with stored procedure.
Here you can find my stored procedure and code for button click.
When I execute project I get this error. Can anyone help me to fix this error.
Stored procedure
create PROCEDURE [dbo].[usp_InsertIntoTable]
@fid int,
@lid int,
@kid int,
@pid int,
@date datetime,
@type nvarchar(50),
@qty nvarchar(50),
@remarks nvarchar(500)
AS
begin
INSERT INTO Table1
VALUES
(
@fid,
@kid,
@pid,
@date,
@type,
@remarks
)
INSERT INTO Table2
VALUES
(
@fid,
@lid,
@qty
)
end
C# code on button click
private void btnSave_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("usp_InsertIntoTable", BaseDAL.Connection);
cmd.CommandType = CommandType.StoredProcedure;
for (int i = 0; i < dgvRez.Rows.Count; i++)
{
cmd.Parameters.Add(new SqlParameter("@fid", dgvRez.Rows[i].Cells["FID"].Value));
cmd.Parameters.Add(new SqlParameter("@lid", dgvRez.Rows[i].Cells["LBook"].Value));
cmd.Parameters.Add(new SqlParameter("@kid", dgvRez.Rows[i].Cells["KClient"].Value));
cmd.Parameters.Add(new SqlParameter("@pid", dgvRez.Rows[i].Cells["PEmployee"].Value));
cmd.Parameters.Add(new SqlParameter("@date", dgvRez.Rows[i].Cells["Date"].Value));
cmd.Parameters.Add(new SqlParameter("@type", dgvRez.Rows[i].Cells["Type"].Value.ToString()));
cmd.Parameters.Add(new SqlParameter("@qty", dgvRez.Rows[i].Cells["Quantity"].Value.ToString()));
cmd.Parameters.Add(new SqlParameter("@remarks", dgvRez.Rows[i].Cells["Remarks"].Value.ToString()));
cmd.ExecuteNonQuery();
}
}