VB.NET DataAdapter.Fill

The DataAdapter serves as a bridge between a DataSet and a data source for retrieving and saving data. The DataAdapter provides this bridge by mapping Fill, which changes the data in the DataSet to match the data in the data source, and Update, which changes the data in the data source to match the data in the DataSet.

The Fill method retrieves rows from the data source using the SELECT statement specified by an associated SelectCommand property. If the data adapter encounters duplicate columns while populating a DataTable, it generates names for the subsequent columns, using the pattern "columnname1", "columnname2", "columnname3", and so on. From the following program you can understand how to use DataAdapter.Fill method in VB.NET applications.

Imports System.IO
Imports System.Data.SqlClient
Public Class Form1
	Dim cnn As SqlConnection
	Dim connectionString As String
	Dim sqlAdp As SqlDataAdapter
	Dim ds As New DataSet
	Dim dt As New DataSet

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim i As Integer
		connectionString = "Data Source=servername; Initial Catalog=databasename; User ID=userid; Password=password"
		cnn = New SqlConnection(connectionString)
		sqlAdp = New SqlDataAdapter("select * from users", cnn)
		cnn.Close() 'connection close here , that is disconnected from data source


		'fetching data from dataset in disconnected mode
		For i = 0 To ds.Tables(0).Rows.Count - 1

		'fetching data from datatable in disconnected mode
		For i = 0 To dt.Tables(0).Rows.Count - 1

	End Sub
End Class (C) 2020    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About