<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.Odbc"%>
<%@ 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 System.Data.Odbc.OdbcConnection
Dim objCmd As New System.Data.Odbc.OdbcCommand
Dim dtAdapter As New System.Data.Odbc.OdbcDataAdapter
Dim ds As New DataSet
Dim strConnString,strSQL As String
strConnString = "DSN=mydatabase;UID=;PWD=;"
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 - System.Data.Odbc</title>
</head>
<body>
<form id="form1" runat="server">
<asp:DataGrid id="myDataGrid" AutoGenerateColumns="true" runat="Server"></asp:DataGrid>
</form>
</body>
</html>