Insert records into the DB using data adapter.
Design a form using .NET environment and place two textbox controls on a form.
Design and create a table using SQL Server 2000.
Name the Database as FinAccounting.
Name the Table as AccountsTable.
Name the form as Form1
Name the controls on the form as Textbox1 and Textbox2.
Tasks:
1. Establish the connection with the database using Connection object.
2. Instantiate the Command object.
3. Instantiate Data Adapter
4. Set Data Adapter command properties
5. Instantiate DataSet
6. Populate the DataSet using the DataAdapter and the data will be displayed in the textboxes.
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim myConnection As SqlConnection = New SqlConnection(âData Source=VSDOTNET;Integrated Security=SSPI;Initial Catalog=FinAccountingâ)
Dim str_sql_account_select As String = âSELECT * FROM AccountsTableâ
Dim comAccountSelect As SqlCommand âcommand for Account select
Dim myAccountAdapter As SqlDataAdapter
Dim myAccountDataset As DataSet
Private Sub frmAccounts_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i, j As Integer
Dim vbn As Boolean
vbn = True
myConnection.Open()
âInstantiate the commands
comAccountSelect = New SqlCommand(str_sql_account_select, myConnection)
âInstantiate data adapter
myAccountAdapter = New SqlDataAdapter(str_sql_account_select, myConnection)
âSet data adapter command properties
myAccountAdapter.SelectCommand = comAccountSelect
âInstantiate the datasets
myAccountDataset = New DataSet()
âPopulate the dataset
myAccountAdapter.Fill(myAccountDataset, âAccountsTableâ)
j = myAccountDataset.Tables(âAccountsTableâ).Rows. Count()
For i = 0 To (j - 1)
TextBox1.Text = myAccountDataset.Tables(âAccountsTableâ).Rows( i)(0)
TextBox2.Text = myAccountDataset.Tables(âAccountsTableâ).Rows( i)(1)
Next
End Sub
End Class
Also, try to refer this book Titled:"Database programming using
vb.net and SQL server 2000"
Regards
Bhar