for (int i = 0; i < dataGridView4.Rows.Count-1; i++)
{
//for (int j = 0; j < dataGridView4.Columns.Count; i++)
//{
//for (int i = 0; i < dataGridView4.HeaderRow.Cells.Count; i++)
//{
dt.Rows.Add(dataGridView4.Rows[i].Cells[0].Value.ToString());
dt.Rows.Add(dataGridView4.Rows[i].Cells[1].Value.ToString());
dt.Rows.Add(dataGridView4.Rows[i].Cells[2].Value.ToString());
dt.Rows.Add(dataGridView4.Rows[i].Cells[3].Value.ToString());
dt.Rows.Add(dataGridView4.Rows[i].Cells[13].Value.ToString());
dt.Rows.Add(dataGridView4.Rows[i].Cells[18].Value.ToString());
dt.Rows.Add(dataGridView4.Rows[i].Cells[19].Value.ToString());
dt.Rows.Add(dataGridView4.Rows[i].Cells[21].Value.ToString());
dt.Rows.Add(dataGridView4.Rows[i].Cells[22].Value.ToString());
dt.Rows.Add(dataGridView4.Rows[i].Cells[23].Value.ToString());
da = new OleDbDataAdapter();
da.Fill(d, "dt");
}
Ramesh MaruthiPosted Aug 12, 2014, 10:46 AM
you need to add the columns first to the data table see this examples
http://stackoverflow.com/questions/15447078/datatable-row-filling-in-c-sharp
http://msdn.microsoft.com/en-us/library/kcy03ww2(v=vs.110).aspx