By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,337 Members | 2,084 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,337 IT Pros & Developers. It's quick & easy.

How to insert Bulk data from Gridview to Database table

P: 1
I have Bulk data ,just want to insert that data from Gridview to Database table how it possible?
I have done this way is it correct?
Expand|Select|Wrap|Line Numbers
  1. protected void btn_insert_Click(object sender, EventArgs e)
  2.  
  3.         {
  4.  
  5.             foreach (GridViewRow g1 in GridView1.Rows)
  6.  
  7.             {
  8.  
  9.                 SqlConnection con = new SqlConnection(connStr);
  10.  
  11.                 com = new SqlCommand("insert into student(sid,sname,smarks,saddress) values ('" + g1.Cells[0].Text + "','" + g1.Cells[1].Text + "','" + g1.Cells[2].Text + "','" + g1.Cells[3].Text + "')", con);
  12.  
  13.                 con.Open();
  14.  
  15.                 com.ExecuteNonQuery();
  16.  
  17.                 con.Close();
  18.  
  19. <!--[if !supportEmptyParas]--> <!--[endif]-->
  20.  
  21.             }
  22.  
  23.             Label1.Text = "Records inserted successfully";
  24.  
  25.         }
  26.  
  27.     }
  28.  
  29. }


Regards
Sree
May 8 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.