Click here to Skip to main content
Rate this: bad
good
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 0: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
0 Sergey Alexandrovich Kryukov 279
1 OriginalGriff 220
2 Peter Leow 205
3 _Amy 190
4 Andreas Gieriet 180
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,412
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,702


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2014
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