<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="MySql.Data.MySqlClient"%>
<%@ 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 MySql.Data.MySqlClient.MySqlConnection
Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand
Dim dtAdapter As New MySql.Data.MySqlClient.MySqlDataAdapter
Dim ds As New DataSet
Dim i As Integer
Dim strConnString,strSQL As String
strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false"
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 - MySql.Data.MySqlClient</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="Server"></asp:Label>
</form>
</body>
</html>