How to insert Bulk data from Gridview to Database table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sreedharmcts
    New Member
    • May 2013
    • 1

    #1

    How to insert Bulk data from Gridview to Database table

    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?
    Code:
    protected void btn_insert_Click(object sender, EventArgs e)
    
            {
    
                foreach (GridViewRow g1 in GridView1.Rows)
    
                {
    
                    SqlConnection con = new SqlConnection(connStr);
    
                    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);
    
                    con.Open();
    
                    com.ExecuteNonQuery();
    
                    con.Close();
    
    <!--[if !supportEmptyParas]--> <!--[endif]-->
    
                }
    
                Label1.Text = "Records inserted successfully";
    
            }
    
        }
    
    }


    Regards
    Sree
    Last edited by Rabbit; May 8 '13, 04:31 PM. Reason: Please use code tags when posting code.
Working...