当前位置: 首页 > 图文教程 > 网络编程 > ASP > sp+语法介绍(六)----数据库篇

ASP
介绍一下GETROWS的用法
一个在vbscript中读取cookie的程序函数
用err.raise自定义错误信息
一段返回随机记录的代码
基于ACCESS数据库的纯asp论坛制作心得
不用Golobal.asa和session实现在线人数统计
在ASP里建表
结束ADOVB.INC的办法
存储过程分页
友情连接浏览器
怎样使用ASP实现Ping
用ASP读取Windows标准INI格式文件
使用ActiveX控件开发网页常见的问题
两个获取http页面的c#函数
将html源代码规范化,转换成XSL代码的asp工具
已调试好的asp程序在VB中转换为组件的技巧
关于如何动态地在同一页面实现两个互传
关于图片与文本同存在数据库中的具体思路
实现分页的例子-使用存储过程来实现分页
使用索引服务器- 使用索引服务器的对象

ASP 中的 sp+语法介绍(六)----数据库篇


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 207 ::
收藏到网摘: n/a

       列表,数据和数据棒定
   asp+ 给我们提供了一套数据表格和数据列表的控件。这些控件可以帮助我们定制我们UI(user interFace 用户界面)而不去考虑一种数据库或者其他的数据库。例如:在下面的例子中,我们将要介绍一下<asp:datagrid runat=server>控件是怎么样通过sql 语句给我们提供数据的
  <%@ Import Namespace="System.Data" %>
  <%@ Import Namespace="System.Data.SQL" %>
  
  <html>
   <head>
   <link rel="stylesheet"href="intro.css">
   </head>
  
   <script language="VB" runat=server>
  
   Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
  
   Dim DS As DataSet
   Dim MyConnection As SQLConnection
   Dim MyCommand As SQLDataSetCommand
   '以下是数据库联结
   MyConnection = New SQLConnection("server=localhost;uid=sa;pwd=;database=pubs")
   MyCommand = New SQLDataSetCommand("select * from Titles where type='" + Category.SelectedItem.Value + "'", myConnection)
  
   DS = new DataSet()
   MyCommand.FillDataSet(DS, "Titles")
  
   MyList.DataSource = DS.Tables("Titles").DefaultView
   MyList.DataBind()
  
   End Sub
  
  
   </script>
  
   <body>
  
   <center>
  
   <form action="intro75.aspx" method="post" runat="server">
  
   <asp:adrotator AdvertisementFile="ads.xml" BorderColor="black" BorderWidth=1 runat="server"/>
  
   <h3> Name: <asp:textbox id="Name" runat="server"/>
  
   Category: <asp:dropdownlist id="Category" runat=server>
   <asp:listitem >psychology</asp:listitem>
   <asp:listitem >business</asp:listitem>
   <asp:listitem >popular_comp</asp:listitem>
   </asp:dropdownlist>
  
   <asp:button type=submit text="Lookup" OnClick="SubmitBtn_Click" runat="server"/>
  
   <p>
  
   <ASP:DataGrid id="MyList" HeaderStyle-BackColor="#aaaadd" BackColor="#ccccff" runat="server"/>
  
   </form>
  
   </center>
  
   </body>
  
  </html>
  这个例子的运行示例在
  http://tutorial.superexpert.com/quickstart/aspplus/samples/webforms/intro/intro75.aspx
  
  数据表格(data grid)控件 <asp:datagrid runat=server>
  给我们提供了一种非常简单的方法用传统的UI截面去显示数据查询的结果.Asp+ 的开发者现在还可以通过<asp:dataList runat=server>
  来定制数据列表显示来定制信息
  
  <%@ Import Namespace="System.Data" %>
  <%@ Import Namespace="System.Data.SQL" %>
  
  <html>
   <head>
   <link rel="stylesheet"href="intro.css">
   </head>
  
   <script language="VB" runat=server>
  
   Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
  
   Dim DS As DataSet
   Dim MyConnection As SQLConnection
   Dim MyCommand As SQLDataSetCommand
  
   MyConnection = New SQLConnection("server=lo