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
Robert replied to undhad ashwin on 12-Nov-10 05:06 PM
Thanks for the reply.

My table is tracking the current time the row was entered and is not allowing NULL.   Even after I removed the allow null flag on the database.  Anyway I could set this field to the current DateTime.Now when I add it? Then updated the columns as you've shown?