How to: Update a DataRow with the Value from a Variable (Visual Basic)
This example assigns the value in the companyName
variable to the CompanyName
data column of dataRow
.
Example
Dim companyName As String = "Microsoft"
Dim dataRow As DataRow = dsNorthwind1.Customers(0)
dataRow("CompanyName") = companyName
Compiling the Code
This example requires:
A project reference to System.data.dll.
Access to the members of the System.Data namespace. Add an Imports statement if you are not fully qualifying member names in your code. For more information, see Imports Statement.
An instance of a typed dataset named
dsNorthwind1
.A data table named
Customers
in thedsNorthwind1
dataset.A DataColumn named
CompanyName
in theCustomers
table.At least one DataRow in the
Customers
table.
Robust Programming
The following conditions may cause an exception:
Assigning a value with the wrong data type (InvalidCastException Class, ArgumentException).
Assigning a value to a primary key field if the primary key already exists in the data table (ConstraintException Class).
See Also
Reference
DataRow Class
DataColumn Class
Concepts
Other Resources
Preparing Your Application to Receive Data
Editing Data in Your Application