Working with ADO.NET - Inserting Records
(Page 3 of 4 )
You can easily add records using a few lines of code. First, create an instance of the DataRow class and call it NewRow() method.
Dim drnew As System.Data.DataRow
drnew = Me.DsCustomers1.customer_list.NewRow()
This will create a blank row in the database. The next step is to bind the relevant column name with the required WinForm control and call the Add() method of Rows collection as shown below.
drnew.Item("Name") = txtName.Text
drnew.Item("E-mail") = txtEmail.Text
Me.DsCustomers1.customer_list.Rows.Add(drnew)
The final step is to update the dataset with the created object of the DataAdapter.
OleDbDataAdapter1.Update(DsCustomers1)
Navigating Records
With ADO.NET, you can move to the next record, previous record, and also directly to the first and last records using a single line of code.
'Navigating Next Record
Me.BindingContext(Me.DsCustomers1, "customer_list").Position += 1
'Navigating Previous Record
Me.BindingContext(Me.DsCustomers1, "customer_list").Position -= 1
'Navigating First Record
Me.BindingContext(Me.DsCustomers1, "customer_list").Position = 0
'Navigating Last Record
With Me.BindingContext(Me.DsCustomers1, "customer_list")
.Position = .Count - 1
End With
Next: Searching Records >>
More .NET Articles
More By Anand Narayanaswamy