
Editing a Record in a DataTable When You Do Not Know the Index of the Row That You Want To Edit
Typically, you do not know the index of the row you want to edit. Data tables in typed datasets are created with a FindBy method that uses the table's primary key to locate a row.
To update existing records in typed datasets (Row index not known)
Assign a specific DataRow to a variable using the generated FindBy method, and then use that variable to access the columns you want to edit and assign new values to them.
In the following example, the CustomerID column is the primary key of the Customers table, so the generated FindBy method is FindByCustomerID.
Dim customersRow As NorthwindDataSet.CustomersRow
customersRow = NorthwindDataSet1.Customers.FindByCustomerID("ALFKI")
customersRow.CompanyName = "Updated Company Name"
customersRow.City = "Seattle"
NorthwindDataSet.CustomersRow customersRow =
northwindDataSet1.Customers.FindByCustomerID("ALFKI");
customersRow.CompanyName = "Updated Company Name";
customersRow.City = "Seattle";;
Typically, you do not know the index of the row you want to edit. Data tables in untyped datasets are created with a Select method that returns an array of DataRows.
To update existing records in untyped datasets (Row index not known)
Use the Select method of the DataTable to locate a specific row and assign new values to the desired columns
In the following example, the CustomerID column is the primary key of the Customers table, so calling the Select method and searching for the primary key will only result in finding one row. The return type is still an array of DataRows, so we access the (0) index, or first row, in the array.
Dim customerRow() As Data.DataRow
customerRow = DataSet1.Tables("Customers").Select("CustomerID = 'ALFKI'")
customerRow(0)("CompanyName") = "Updated Company Name"
customerRow(0)("City") = "Seattle"
DataRow[] customerRow =
dataSet1.Tables["Customers"].Select("CustomerID = 'ALFKI'");
customerRow[0]["CompanyName"] = "Updated Company Name";
customerRow[0]["City"] = "Seattle";