Dataadapter with dataset - sql sever

The SqlDataAdapter serves as a crucial intermediary, facilitating seamless communication between the Dataset and the Data Source by utilizing the SqlConnection Object. The SqlConnection Object, by itself, possesses no intrinsic knowledge about the data it retrieves. Similarly, the Dataset is unaware of the specific Data Source from which the data originates. Consequently, it is the responsibility of the SqlDataAdapter to effectively manage the communication and coordination between these two distinct entities.

One of the primary functionalities of the SqlDataAdapter is to populate Data Tables within a Dataset. This is achieved through the utilization of the Fill method provided by the SqlDataAdapter. By employing the Fill method, we can seamlessly retrieve data from the Data Source using the SqlConnection object and populate the acquired data into the corresponding Data Tables within the Dataset.

To illustrate this process, consider the following source code snippet, which showcases a simple program that utilizes the SqlDataAdapter to retrieve data from the Data Source. The program utilizes the SqlConnection object to establish a connection with the Data Source and subsequently employs the Fill method to populate the retrieved data into the relevant Data Tables within the Dataset.

Full Source VB.NET
Imports System.Data.SqlClient Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connetionString As String Dim connection As SqlConnection Dim adapter As SqlDataAdapter Dim ds As New DataSet Dim i As Integer connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password" connection = New SqlConnection(connetionString) Try connection.Open() adapter = New SqlDataAdapter("Your SQL Statement Here", connection) adapter.Fill(ds) connection.Close() For i = 0 To ds.Tables(0).Rows.Count - 1 MsgBox(ds.Tables(0).Rows(i).Item(1)) Next Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class