You can insert multiple row by creating Type of Table in Sql and pass the DataTable to Procedure
CREATE TYPE _table AS TABLE
(
Id INT,
Name VARCHAR(100),
DOCUMENT VARCHAR(200)
)
Alter You Procedure
ALTER PROC sp_Insert
(
@tablevariable _table READONLY
)
AS
BEGIN
INSERT INTO YourTable(Id,Name,Document) SELECT Id,Name,Document FROM @tablevariable
END
Code Change
if (gvSample!= null)
{
DataTable _dt = new DataTable();
_dt.Columns.Add("Id");
_dt.Columns.Add("Name");
_dt.Columns.Add("Document");
for (int i = 0; i < gvSample.Rows.Count; i++)
{
GridViewRow row = this.(gvSample.Rows[i]);
_dt.Rows.Add(gvSample.Rows[i].Cells[0].Text,gvSample.Rows[i].Cells[1].Text, gvSample.Rows[i].Cells[2].Text);
}
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_Insert";
cmd.Parameters.AddWithValue("@tablevariable", _dt );
cmd.ExecuteNonQuery();
}
refrence:
[
Insert Bulk Row at a time]