一个用asp+存取数据库的例子
类别: ASP教程
<%@ Page Language="VB"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>
<script language="VB" runat="server">
Sub subbtn_OnClick(Sender As Object, E As EventArgs)
Dim connobj As ADOConnection
Dim dtsCmdobj As ADODataSetCommand
Dim dtSobj As DataSet
Dim str_sql As String
dim conn_str As String
str_sql = "select * from table_name"
conn_str = "DBQ=" & Server.MapPath("database.mdb") &_
";Driver={Microsoft Access Driver (*.mdb)};"
connobj = New ADOConnection(conn_str)
dtsCmdobj = New ADODataSetCommand(str_sql, connobj)
dtSobj = New DataSet()
dtsCmdob.FillDataSet(dtsobj, "table_name")
dtgrid.DataSource = dtsobj.Tables("table_name").DefaultView
dtgrid.DataBind()
End Sub
</script>
<html>
<body>
<form action="db.aspx" method="post" runat="server">
<asp:Button type="submit" id="subbtn" text="Run Query" OnClick="subbtn_OnClick" runat="server" />
</form>
<asp:DataGrid id="dtgrid" HeaderStyle-Font-Bold="True" ToolTip="data Grid provided with asp+" runat="server" maintainviewstate="false" />
</body>
</html>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>
<script language="VB" runat="server">
Sub subbtn_OnClick(Sender As Object, E As EventArgs)
Dim connobj As ADOConnection
Dim dtsCmdobj As ADODataSetCommand
Dim dtSobj As DataSet
Dim str_sql As String
dim conn_str As String
str_sql = "select * from table_name"
conn_str = "DBQ=" & Server.MapPath("database.mdb") &_
";Driver={Microsoft Access Driver (*.mdb)};"
connobj = New ADOConnection(conn_str)
dtsCmdobj = New ADODataSetCommand(str_sql, connobj)
dtSobj = New DataSet()
dtsCmdob.FillDataSet(dtsobj, "table_name")
dtgrid.DataSource = dtsobj.Tables("table_name").DefaultView
dtgrid.DataBind()
End Sub
</script>
<html>
<body>
<form action="db.aspx" method="post" runat="server">
<asp:Button type="submit" id="subbtn" text="Run Query" OnClick="subbtn_OnClick" runat="server" />
</form>
<asp:DataGrid id="dtgrid" HeaderStyle-Font-Bold="True" ToolTip="data Grid provided with asp+" runat="server" maintainviewstate="false" />
</body>
</html>
- 上一篇: 查看主机的内存使用情况
- 下一篇: 用asp.net写的论坛程序
-= 资 源 教 程 =-
文 章 搜 索