论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > asp教程
Tag:入门,文摘,实例,技巧,iis,表单,对象,上传,数据库,记录集,session,cookies,存储过程,注入,分页,安全,优化,xmlhttp,fso,jmail,application,防盗链,stream,组件,md5,乱码,缓存,加密,验证码,算法,ubb,正则表达式,水印,,日志,压缩,url重写,控件,函数,破解,触发器,socket,ADO,初学,聊天室,留言本,视频教程

Asp+语法介绍(六)----数据库篇

文章类别:asp | 发表日期:2008-10-5 20:37:13


  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=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="intro8.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:datalist id="MyList" repeatcolumns="2" borderwidth="0" runat="server">

             <template name="itemtemplate">

                 <table>
                   <tr>

                     <td>
                         <img src='<%# DataBinder.Eval
(Container.DataItem, "title_id", "/quickstart/aspplus/images/title-{0}.gif") %>'>
                     </td>

                     <td width=250 valign=top>

                         <b><%# DataBinder.Eval(Container.DataItem, "title") %></b>

                         <br><br>

                         Price: <%# DataBinder.Eval(Container.DataItem, "price", "${0}") %>
                     </td>

                   </tr>
                 </table>

             </template>

           </asp:datalist>

       </form>

       </center>

   </body>

</html>


这个程序的运行例子在
http://tutorial.superexpert.com/quickstart/aspplus/samples/webforms/intro/intro8.aspx
视频教程列表
文章教程搜索
 
Asp推荐教程
Asp热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058