yes u can use the same dataset and adapter.If I wanted to write a second Sql query for another object on the form, would I be creating a new adapter with sql code and adding it to the same dataset?
Declarations
used it to fill Categories table to datasetCode:Dim conn As New SqlConnection("Server=CHEETAH;Database=NorthWind;Trusted_Connection=True;") Dim adapter As SqlDataAdapter Dim ds As New DataSet()
used it to fill Employees table to datasetCode:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click adapter = New SqlDataAdapter("select * FROM Categories", conn) ds = New DataSet() conn.Open() adapter.Fill(ds, "Categories") conn.Close() Me.DataGridView1.DataSource = ds.Tables("Categories") End Sub
When u use to fill data to dataset filled before, previous data clears and adapter fill new data in the dataset.Code:Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click adapter = New SqlDataAdapter("select * FROM Employees", conn) ds = New DataSet() conn.Open() adapter.Fill(ds, "Employees") conn.Close() Me.DataGridView1.DataSource = ds.Tables("Employees") End Sub
u can also clear the dataset using the clear method of dataset.




Reply With Quote