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.
DataAdapter.Fill(DataSet)
DataAdapter.Fill(DataTable)
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)
cnn.Open()
sqlAdp = New SqlDataAdapter("select * from users", cnn)
cnn.Close() 'connection close here , that is disconnected from data source
sqlAdp.Fill(ds)
sqlAdp.Fill(dt)
'fetching data from dataset in disconnected mode
For i = 0 To ds.Tables(0).Rows.Count - 1
MsgBox(ds.Tables(0).Rows(i).Item(0))
Next
'fetching data from datatable in disconnected mode
For i = 0 To dt.Tables(0).Rows.Count - 1
MsgBox(dt.Tables(0).Rows(i).Item(0))
Next
End Sub
End Class