ADO.NET Code showing Dataset storing multiple tables
- Declare and initialize database connection object with appropriate connection string.
- Create a DataAdapter and a Dataset object.
- Using fill method of the DataAdapter object, load the data into the Dataset Object.
- Change the adapter's SELECT command.
- Create the EmpDetail table.
- Add both tables to a single dataset.
- Display the data using data binding feature of controls like Datagrid or Datalist.
Dim m_adptEmp As SqlDataAdapter
Private Sub Page_Load(ByVal sender As System.Object, _ByValeAsSystem.EventArgs)HandlesMyBase.Load<BR> DimEmpConnAsNewSqlConnection_<BR> ("server=(local);database=Employees;Trusted_Connection=yes")
m_adptEmp = New SqlDataAdapter("select * from Emp", EmpConn)
Dim dsEmp As New DataSet
m_adptEmp.Fill(dsEmp, "Emp")
adptEmp.SelectCommand.CommandText = "SELECT * FROM EmpDetail"
Dim EmpDetail As New DataTable("EmpDetail")
adptDB.Fill(EmpDetail)
dsBoth.Tables.Add(Emp)
dsBoth.Tables.Add(EmpDetail)
DataGrid1.DataSource = dsEmp.Tables("Emp").DefaultView
DataGrid1.DataBind()
End Sub