I have a gridview which will contain some \'n\' number of rows.... Now i want to add all rows of the gridview to a datatable which will be used for bulkcopy operation...
you can traverse datagrid row by row and make a comma separated file. then use Bulk insert or bcp for inserting data to db.
Another Solution
DataTable dt = new DataTable();
for (int j = 0; j < grdList.Rows.Count; j++)
{
DataRow dr;
GridViewRow row = grdList.Rows[j];
dr = dt.NewRow();
for (int i = 0; i < row.Cells.Count; i++)
{
dr[i] = row.Cells[i].Text;
}
dt.Rows.Add(dr);
}
SqlBulkCopy sbc = new SqlBulkCopy(targetConnStr);
sbc.DestinationTableName = "yourDestinationTable";
sbc.WriteToServer(dt);
sbc.Close();