hello guys
I am developing project in MVC5.
how to add multiple rows and save all the records with a single button (save records in the database.)
hello guys
I am developing project in MVC5.
how to add multiple rows and save all the records with a single button (save records in the database.)
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Srinivasan RamamoorthiRank #877 · 2.5K reputationPosted Nov 8, 2021, 9:21 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Nov 8, 2021, 1:25 PM EST
If you are using ADO.NET
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Id", typeof(string)));
dt.Columns.Add(new DataColumn("Name", typeof(string)));
foreach (var entry in entries)
dt.Rows.Add(new string[] { entry.Id, entry.Name });
using (SqlBulkCopy bc = new SqlBulkCopy(connection))
{ // the following 3 lines might not be neccessary
bc.DestinationTableName = "Entries";
bc.ColumnMappings.Add("Id", "Id");
bc.ColumnMappings.Add("Name", "Name");
bc.WriteToServer(dt);
}
For EntityFramework
YourContext.Employees.AddRange(
yourEmployeeList //List
);
For Dapper
using (var conn = new SqlConnection(cs))
{
var affectedRows = await conn.ExecuteAsync("insert into tblEmployee values(@Name,@Salary)", yourEmployeeList);
}
//Note:- parameter Name must match to your Employee class properties name