Protected void SaveGrid
{
int RowsCount = dgvsales.Rows.Coun t;
int ColumnsCount = dgvsales.Columns.Count;
for(int i =0;i < rowsCount;i++)
{
for(int j=1;j < ColumnsCount ; j+=)
{
I want to get data of each cell in a row
I want to read the corresponding Header and store
}
please check the code and correct it,i have to save different columns through gridview in sql 2005 when i added,all the certain columns created in grid view edit columns.example : itemcode,itemname,Nos,Rate,Amount these are in grid
i should save different 'itemname' into corresponding seperate columns through itemname in the grid.please give me soon.
Loading
Sanjeeb LenkaPosted Sep 27, 2013, 6:03 AM
try like this:
string StrQuery;
try
{
using (SqlConnection conn = new SqlConnection(ConnString))
{
using (SqlCommand comm = new SqlCommand())
{
comm.Connection = conn;
conn.Open();
for(int i=0; i< dataGridView1.Rows.Count;i++)
{
StrQuery= @"INSERT INTO tableName VALUES ("
+ dataGridView1.Rows[i].Cells["ColumnName"].Value +", "
+ dataGridView1.Rows[i].Cells["ColumnName"].Value +");";
comm.CommandText = StrQuery;
comm.ExecuteNonQuery();
}
}
}
}or you can refer to this link
http://aspdotnetwithcsharperrors.blogspot.in/2012/02/bulk-insert-and-update-from-gridview.html