IDE:Visual Web Developer 2008 Express Edition
DB:Access 2007
aaa.aspx.vb
Protected Sub btnSearch_Click(ByVal sender As Object,ByVal e As EventArgs) Handles btnSearch.Click Dim myConnection As OleDbConnection Dim myCommand As OleDbCommand Dim dbname As String dbname = Server.MapPath("location.accdb") myConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;DATA Source=" & dbname) myConnection.Open() myCommand = New OleDbCommand("SELECT * FROM tableName",myConnection) MyDataGrid.DataSource = myCommand.ExecuteReader() MyDataGrid.DataBind() End Sub
aaa.aspx
<asp:DataGrid id="MyDataGrid" runat="server" Font-Name="Verdana" Font-Size="10pt" HeaderStyle-BackColor="#aaaadd" AlternatingItemStyle-BackColor="#eeeeee" Font-Names="Verdana" PageSize="50" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None" AllowCustomPaging="True" Width="100%"> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditItemStyle BackColor="#2461BF" /> <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <AlternatingItemStyle BackColor="White"></AlternatingItemStyle> <ItemStyle BackColor="#EFF3FB" /> <Columns> <asp:TemplateColumn HeaderText="No"> <ItemTemplate> <%#Container.DataSetIndex + 1%> </ItemTemplate> </asp:TemplateColumn> </Columns> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"></HeaderStyle> </asp:DataGrid>