We need to create the datacolumn from the datagridview column.Add created Column in to datatable .Add the datatable in to dataset.loop through the datagridview add data to datatable .
DataTable table = new DataTable("mytable");
DataColumn column;
DataRow row;
DataSet dataset = new DataSet();
column = new DataColumn();
column.DataType = dataGridView1.Columns[0].ValueType;
column.ColumnName = dataGridView1.Columns[0].Name;
table.Columns.Add(column);
column = new DataColumn();
column.DataType = dataGridView1.Columns[1].ValueType;
column.ColumnName = dataGridView1.Columns[1].Name;
table.Columns.Add(column);
dataset.Tables.Add(table);
for (int rowCount = 0; rowCount < dataGridView1.Rows.Count - 1; rowCount++)
{
row = table.NewRow();
row[0] =Convert.ToInt32(dataGridView1.Rows[rowCount].Cells[0].Value);
row[1] = dataGridView1.Rows[rowCount].Cells[1].Value.ToString();
table.Rows.Add(row);
}
return dataset;