1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ODBC" %>
<script language="VB" Runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
BindData
End Sub
Sub BindData()
Dim strConn As String
strConn = "DRIVER={MySQLODBC 3.51 Driver};ServerAddress = localhost;DATABASE=hi;" & _
"USER=root;PASSWORD=; OPTION=16386;"
Dim MySQL As String = "Select * " & _
" from moi"
Dim MyConn As New ODBCConnection(strConn)
Dim ds As DataSet = New DataSet()
Dim Cmd As New ODBCDataAdapter(MySQL, MyConn)
Cmd.Fill(ds, "moi")
MyDataGrid.DataSource = ds.Tables("moi").DefaultView
MyDataGrid.DataBind()
End Sub
Sub Page_Change(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MySQL with ASP.Net</title>
<meta name="GENERATOR" content="asp express 4.0"/>
</head>
<body>
<form id="form1" runat="server">
<asp:Datagrid Runat="server"
Id="MyDataGrid">
</asp:Datagrid>
</form>
</body>
</html> |
Partager