What is SqlDataAdapter

The SqlDataAdapter is an integral component of the ADO.NET Data Provider and is located within the System.Data.SqlClient namespace. It serves as a bridge between the Dataset and the SQL database, facilitating communication and interaction between the two.

To utilize the functionality provided by the SqlDataAdapter, it is commonly used in conjunction with the Dataset Object. The SqlDataAdapter and Dataset work together to enable data access and manipulation operations within the SQL Server Database.

Dim adapter As New SqlDataAdapter

When a user performs SQL operations, such as Select or Insert, on the data stored within the Dataset Object, these operations do not directly impact the underlying Database. Instead, the changes made to the Dataset are isolated within its internal representation.

To synchronize the changes made in the Dataset with the actual Database, the user needs to invoke the Update method provided by the SqlDataAdapter. The Update method is responsible for propagating the changes from the Dataset back to the Database.

SqlDataAdapter

Calling the Update method, the SqlDataAdapter analyzes the changes within the Dataset, determines the corresponding SQL statements required to apply those changes to the Database, and executes them accordingly. This process ensures that the data modifications made in the Dataset are reflected in the underlying SQL Server Database.

The SqlDataAdapter offers a convenient and efficient way to manage data access and manipulation operations. It provides a layer of abstraction that simplifies the interaction with the Database and enhances data integrity.

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 sqlCnn As SqlConnection Dim sqlCmd As SqlCommand Dim adapter As New SqlDataAdapter Dim ds As New DataSet Dim i As Integer Dim sql As String connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserNamePassword=Password" sql = "Select * from product" sqlCnn = New SqlConnection(connetionString) Try sqlCnn.Open() sqlCmd = New SqlCommand(sql, sqlCnn) adapter.SelectCommand = sqlCmd adapter.Fill(ds) For i = 0 To ds.Tables(0).Rows.Count - 1 MsgBox(ds.Tables(0).Rows(i).Item(0) & " -- " & ds.Tables(0).Rows(i).Item(1)) Next adapter.Dispose() sqlCmd.Dispose() sqlCnn.Close() Catch ex As Exception MsgBox("Can not open connection ! ") End Try End Sub End Class
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
sql = "Select * from product"

You have to replace the string with your realtime variables.