Hi MaerskOw,
I have created sample code which fullfill requirement.
HTML
<div>
<asp:Button Text="Insert" OnClick="Insert" runat="server" />
</div>
C#
private string Constr = ConfigurationManager.ConnectionStrings["Constring"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Country", typeof(string));
dt.Rows.Add("Peter", "USA");
dt.Rows.Add("John", "Franch");
Session["Customers"] = dt;
}
protected void Insert(object sender, EventArgs e)
{
DataTable dtCustomers = Session["Customers"] as DataTable;
SqlConnection con = new SqlConnection(Constr);
con.Open();
foreach (DataRow row in dtCustomers.Rows)
{
SqlCommand cmd = new SqlCommand("INSERT INTO Customers Values(@Name,@Country)", con);
cmd.Parameters.AddWithValue("@Name", row["Name"]);
cmd.Parameters.AddWithValue("@Country", row["Country"]);
cmd.ExecuteNonQuery();
}
con.Close();
}
I hope works for you.