Adding and Removing Data

At this point, the schema of the DataSet is entered and you're ready to add some data. Recall that the column collection of the DataTable defines the schema, and the rows collection of the DataTable defines the data. In other words, to add data to our DataTable, all we need to do is add some rows to our DataTable: dtEmployees.

DataRows Contain Data

Adding rows to the dtEmployees DataTable is easy to do. First, you need to use the NewRow() method of the dtEmployees object. NewRow() returns a reference to a new row for your DataTable. Next, you must specify values for the columns in the newly created row. Lastly, you must add the row to the DataTable. Listings 2.3 and 2.4 demonstrate this by adding a few rows to our existing ...

Get Sams Teach Yourself ADO.NET in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.