C# .NET - Adding row to dataset
Asked By Robert on 12-Nov-10 01:43 PM
Selected all the records from the database into a dataset and populating a datagrid with the data.
How do I add a row to the dataset, commit the row to the database and update my grid?
DataSet = PeopleDS
Columns = First_Name, Last_Name
I don't know what to put in for ???? for the add
PeopleDS.Tables.Add(????)
row = ????.NewRow
row[First_Name] = "John"
row[Last_Name] = "Smith"
????.Rows.Add.(row);
undhad ashwin replied to Robert on 12-Nov-10 01:58 PM
Hi
Try Below code
// Datarow object create your dataset or datatable new row using NewRow() methods
DataRow dr = PeopleDS.Tables[0].NewRow();
// If New Rows created then after u add current dataset or datatable
ds.Tables[0].Rows.Add(dr);
// Then after u can set new data as u r requirement
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0] = "ashwin";
if any issue then reply