<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ 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.SqlClient.SqlConnection
Dim objCmd As New System.Data.SqlClient.SqlCommand
Dim dtAdapter As New System.Data.SqlClient.SqlDataAdapter
Dim ds As New DataSet
Dim strConnString,strSQL As String
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
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.SqlClient</title>
</head>
<body>
<form id="form1" runat="server">
<asp:DataGrid id="myDataGrid" AutoGenerateColumns="true" runat="Server"></asp:DataGrid>
</form>
</body>
</html>