Beginning ASP.NET 2.0 and Databases学习笔记(1)

 Chapter 2

使用AccessDataSource控件

 

示例:

<asp:AccessDataSource ID="NorthwindProductsAccDataSource" runat="server"

            DataFile="~/App_Data/Northwind.mdb"

            SelectCommand="SELECT * FROM [Products]"></asp:AccessDataSource>

        <asp:GridView ID="NorthwindProductsGridVIew" runat="server"

            AutoGenerateColumns="False"

            DataKeyNames="ProductID"

            DataSourceID="NorthwindProductsAccDataSource">

            <Columns>

                <asp:BoundField DataField="ProductID" HeaderText="ProductID"

                    InsertVisible="False"

                    ReadOnly="True"

                    SortExpression="ProductID" />

                <asp:BoundField DataField="ProductName" HeaderText="ProductName"

                    SortExpression="ProductName" />

                <asp:BoundField DataField="SupplierID" HeaderText="SupplierID"

                    SortExpression="SupplierID" />

                <asp:BoundField DataField="CategoryID" HeaderText="CategoryID"

                    SortExpression="CategoryID" />

                <asp:BoundField DataField="QuantityPerUnit"

                    HeaderText="QuantityPerUnit"

                    SortExpression="QuantityPerUnit" />

                <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice"

                    SortExpression="UnitPrice" />

                <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock"

                    SortExpression="UnitsInStock" />

                <asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder"

                    SortExpression="UnitsOnOrder" />

                <asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel"

                    SortExpression="ReorderLevel" />

                <asp:CheckBoxField DataField="Discontinued"

HeaderText="Discontinued"

                    SortExpression="Discontinued" />

            </Columns>

        </asp:GridView>

   

 

或者用事件方法取得数量连接:

<asp:AccessDataSource ID="AccessDataSource1" runat="server"

DataFile="~/App_Data/Northwind.mdb"

SelectCommand="SELECT * FROM [Products]"

OnSelected="AccessDataSource1_Selected"   >

</asp:AccessDataSource>

 

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">

    Sub AccessDataSource1_Selected(ByVal sender As Object, ByVal e As
SqlDataSourceStatusEventArgs)
        If (Not e.Exception Is Nothing) Then
            If TypeOf e.Exception Is System.Data.OleDb.OleDbException Then
                Message.Text = "There was a problem opening a connection to the
database. Please contact the system administrator for this site."
                ' Optionally set GridView1.Visible = false
                e.ExceptionHandled = True
            End If
        End If
    End Sub
</script>
<html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值