hello all
suppose I have fill a datagridview (named it mydgv)
,Can I populate a dataset with the data from the content of mydgv ?
if yes how
thank you
denny
hello all
suppose I have fill a datagridview (named it mydgv)
,Can I populate a dataset with the data from the content of mydgv ?
if yes how
thank you
denny
Just tell me how would you want to populate the dataset( means do you want to populate the dataset row by row of datagridview or do you want to populate the whole dataset from the datagridview at single time)?
hi Shridarmaster
Don't care about row by row or whole in a time
both will be usefull to me
thank you
denny
1st you need to create columns, then you fill the row (by looping through rows of dgv):
DataSet ds = new DataSet();
DataTable table = new DataTable("DataFromDGV");
//if you have only one table, it pointless to create a dataSet
//dataSet is used as a collection of more-then-one dataTable
//so you can do:
ds.Tables.Add(table);
//create columns:
foreach(DataGridViewColumn col in dgv.Columns)
table.Columns.Add(col.HeaderText, typof(string));
//fill the rows of table:
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
table.Rows[row.Index][cell.ColumnIndex] = cell.Value;
}
}
Hi Mitja Bonca
Thank you
denny
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.