<%@ 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 ***'
Dim ds As DataSet
ds = CreateDataSet()
'*** Adding Rows to DataSet ***'
Dim dr As DataRow
dr = ds.Tables("customer").NewRow()
dr.Item("CustomerID") = "C005"
dr.Item("Name") = "Weerachai Nukitram"
dr.Item("Email") = "[email protected]"
dr.Item("CountryCode") = "TH"
dr.Item("Budget") = "2000000"
dr.Item("Used") = "100000"
ds.Tables("customer").NewRow()
ds.Tables("customer").Rows.Add(dr)
'*** Adding Rows to DataSet ***'
Me.myDataGrid.DataSource = ds.Tables(0).DefaultView
Me.myDataGrid.DataBind()
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 strConnString,strSQL As String
strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false"
strSQL = "SELECT * FROM customer "
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds,"customer")
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:DataGrid id="myDataGrid" AutoGenerateColumns="true" runat="Server"></asp:DataGrid>
</form>
</body>
</html>