动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 在ASP+中访问数据库

作者:Gopikrishna 来源:Gopikrishna 
阅读 4160 人次 , 2000-12-21 


In an ASP+ page ,databases can be accessed by employing ADO+ objects. In order to retrieve values from
databases through ADO+ we have to follow certain procedures which are different from those employed in ADO.

The article throws Light on Various steps involved in using ADO+ in an ASP page for retrieving the
database values for an access database.

The datagrid control provided with ASP+ is used for displaying the values retrieved from the database.

First include the language in which the asp+ page will be coded. This is specified by using Page directive
as shown below. In this example Let us use 'VB' as The language for coding ASP+ Page. The above thing can
be achieved by using the following page directive as shown below.

<%@ Page Language="VB"%>


Next Import the namespaces required for creating the Datasetcommand object and Other ADO objects such as
connection , dataset. This can be done by the following asp+ statements

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>


Next create the script required for accessing the database. In this example let us use a server side
submit control whose onClick triggers The script given below

<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>


Finally place the following html in the asp+ code

<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>

Thats it! The datagrid control in ASP+ page is filled up with the values retrieved from the access
database (database.mdb)

Gopikrishna S
Gopikrishna is a specialist in ASP, MTS ,JavaScript , Vbscript, Windows DNA and VBCom . He is currently
associated with Silverline Technologies Limited Chennai.

  

 本文Tags数据库  C#  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:通过事例学习.net的WebForms技术(一)
· 下一篇:利用.NET框架简化发布和解决DLL Hell问题(2)
· 使用 C# 编写扩展存储过程
· 一个简单的ASP.NET Forms 身份认证
· ASP.NET可交互式位图窗体设计(1)
· 全面剖析VB.NET(2)
· ASP.NET中利用存储过程实现模糊查询


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077