Monday, April 5, 2010

Asp.net 4.0 Accessing access database queries in gridview

<%

@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml">

<

head runat="server">

<title></title>

</

head>

<

body>

<form id="form1" runat="server">

<div>

<br />

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"

DataSourceID="AccessDataSource2" DataTextField="Owner" DataValueField="Owner">

</asp:DropDownList>

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

DataFile="S:\CertificatesDB.mdb"

SelectCommand="SELECT distinct [Owner] FROM [500a1: Daily Report]">

</asp:AccessDataSource>

<br />

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

DataSourceID="AccessDataSource1">

<Columns>

<asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" />

<asp:BoundField DataField="Store" HeaderText="Store" SortExpression="Store" />

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

SortExpression="CityState" />

<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />

<asp:BoundField DataField="UPC" HeaderText="UPC" SortExpression="UPC" />

<asp:BoundField DataField="Sales" HeaderText="Sales" SortExpression="Sales" />

<asp:BoundField DataField="Units" HeaderText="Units" SortExpression="Units" />

</Columns>

</asp:GridView>

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

DataFile="S:\CertificatesDB.mdb"

SelectCommand="SELECT * FROM [500a1: Daily Report] WHERE ([Owner] = ?)">

<SelectParameters>

<asp:ControlParameter ControlID="DropDownList1" Name="Owner"

PropertyName="SelectedValue" Type="String" />

</SelectParameters>

</asp:AccessDataSource>

</div>

</form>

</

body>

</

html>

No comments: