Click here to Skip to main content
12,631,606 members (32,012 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
Hi All,

Please help me ...

i have gridview having multiple rows and i want to save all data of the gridview into database at a time ,
ie., without looping

how can i do it?
Posted 29-Nov-12 1:37am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Are you using the entity framework? This is possible if you use an EntityDataSource instead of a SqlDataSource. When you get the data in the code behind, you can just attach it to an entity context.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[0].Value == null && row.Cells[1].Value == null && row.Cells[2].Value == null && row.Cells[3].Value == null && row.Cells[4].Value == null && row.Cells[5].Value == null && row.Cells[6].Value == null && row.Cells[7].Value == null)
{

}
else
{
con.Open();
OleDbCommand cmd = new OleDbCommand("insert into Sold(Product_name,Model_no,Seater,Leather,Colour,Unit_price,Quantity,Total,Advancepayment,Duespayment) values (@Product_name,@Model_no,@Seater,@Leather,@Colour,@Unit_price,@Quantity,@Total,@Advancepayment,@Duespayment)", con);

cmd.Parameters.AddWithValue("@Product_name", row.Cells[0].Value.ToString());
cmd.Parameters.AddWithValue("@Model_no", row.Cells[1].Value.ToString());
cmd.Parameters.AddWithValue("@Seater", row.Cells[2].Value.ToString());
cmd.Parameters.AddWithValue("@Leather", row.Cells[3].Value.ToString());
cmd.Parameters.AddWithValue("@Colour", row.Cells[4].Value.ToString());
cmd.Parameters.AddWithValue("@unit_price", row.Cells[5].Value.ToString());
cmd.Parameters.AddWithValue("@Quantity", row.Cells[6].Value.ToString());
cmd.Parameters.AddWithValue("@Total", row.Cells[7].Value.ToString());
cmd.Parameters.AddWithValue("@Advancepayment", textBox4.Text);
cmd.Parameters.AddWithValue("@Duespayment", label35.Text);

cmd.ExecuteNonQuery();
}
}

i don't know dear without looping so....
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161205.3 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100