<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
BindData()
End Sub
Sub BindData()
'*** DataSet From DataSet ***'
Dim ds As DataSet
ds = CreateDataSet()
Dim i As Integer
Dim dg As DataGrid
Dim lbl As Label
For i = 0 To ds.Tables.Count - 1
dg = New DataGrid
With dg
.DataSource = ds.Tables(i).DefaultView
.AutoGenerateColumns = True
.DataBind()
End With
lbl = New Label
lbl.Text = "<br><b>"&ds.Tables(i).ToString & "</b><br>"
Me.lblText.Controls.Add(lbl)
Me.lblText.Controls.Add(dg)
dg = Nothing
Next
End Sub
'*** DataSet ***'
Function CreateDataSet() As DataSet
Dim objConn As New System.Data.OleDb.OleDbConnection
Dim objCmd As New System.Data.OleDb.OleDbCommand
Dim dtAdapter As New System.Data.OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim i As Integer
Dim strConnString,strSQL As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
Server.MapPath("database/mydatabase.mdb")&";Jet OLEDB:Database Password=;"
Dim TablesName(2) As String
TablesName(0) = "customer"
TablesName(1) = "audit"
TablesName(2) = "country"
For i = 0 To TablesName.GetUpperBound(0)
strSQL = "SELECT * FROM " & TablesName(i) & " "
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds,TablesName(i))
Next
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Return ds '*** Return DataSet ***'
End Function
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - System.Data.OleDb</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="Server"></asp:Label>
</form>
</body>
</html>