简单教程
提交运行
代码编辑器:
<%@ Import Namespace="System.Data.OleDb" %> <script runat="server"> sub Page_Load dim dbconn,sql,dbcomm,dbread dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("/db/northwind.mdb")) dbconn.Open() sql="SELECT * FROM customers" dbcomm=New OleDbCommand(sql,dbconn) dbread=dbcomm.ExecuteReader() customers.DataSource=dbread customers.DataBind() dbread.Close() dbconn.Close() end sub </script> <!DOCTYPE html> <meta charset="utf-8" /> <form runat="server"> <asp:DataList id="customers" runat="server" cellpadding="2" cellspacing="2" borderstyle="inset" backcolor="#e8e8e8" width="100%" headerstyle-font-name="Verdana" headerstyle-font-size="12pt" headerstyle-horizontalalign="center" headerstyle-font-bold="True" itemstyle-backcolor="#778899" itemstyle-forecolor="#ffffff" footerstyle-font-size="9pt" footerstyle-font-italic="True"> <HeaderTemplate> Customers Table </HeaderTemplate> <ItemTemplate> <%#Container.DataItem("companyname")%> in <%#Container.DataItem("address")%>, <%#Container.DataItem("city")%> </ItemTemplate> <FooterTemplate> Source: Northwind Database </FooterTemplate> </asp:DataList> </form>
运行结果: