Adding Data to a DataSet

If you use controls like the Windows Forms DataGrid, adding rows to a table is as easy as navigating to the last position in the DataGrid. The DataGrid will insert the row automatically. Unfortunately this approach doesn't work for Web applications; you will need to know the mechanics for inserting new rows. That capability involves creating a blank row with the same schema as the table it will reside in and adding the row to the DataTable, as demonstrated in Listing 11.11.

Listing 11.11. Adding a New Row Programmatically
 Private Sub ButtonAdd_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles ButtonAdd.Click Dim Row As DataRow = Customers.Tables(0).NewRow() Row("CustomerID") = "HELLO" Row("CompanyName") ...

Get Visual Basic® .NET Power Coding 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.