Sort and group asp.GridView from access database NOT SQL server RRS feed

  • Question

  • User389883181 posted

    I have looked all over the web (well most of it :-) and can't find the answer so....

    I have a gridview with data from an access database THIS NOT AN SQL DATABASE.

    I want to group the gridview by one of the fields.

    Does anyone have a link to any site with instructions on how to do this for with an access database NOT SQL Server.


    It would be something like this (to sort on Shop_type)

    <!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">
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Untitled 1</title>
    <style type="text/css">
    <form id="form1" runat="server">
    <asp:GridView runat="server" id="GridView1"  AutoGenerateColumns="False" DataSourceID="AccessDataSource1">
    		<asp:boundfield  DataField="Shop_type" HeaderText="Shop Type" SortExpression="Shop_type">
    		<asp:boundfield DataField="Shop_name" HeaderText="Shop name" InsertVisible="False" SortExpression="Shop_name">
    	<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="Shops.mdb" SelectCommand="SELECT [Shop_Type], [Shop_name] FROM [tableshops] ORDER BY [Shop_name]">


    Wednesday, August 17, 2016 4:57 PM


All replies

  • User-718146471 posted

    You certainly can group by in MS Access. what you have to do is first group by then order by. here is an example:

    "SELECT Title, Count(Title) AS Tally FROM Employees WHERE Region = 'WA' GROUP BY Title ORDER BY Title;"

    For more details, please refer to https://msdn.microsoft.com/en-us/library/bb177905(v=office.12).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 17, 2016 5:27 PM
  • User-718146471 posted

    So in your case:

    SELECT [Shop_Type], [Shop_name] FROM [tableshops] GROUP BY [Shop_name] ORDER BY [Shop_name]

    That should work.

    Wednesday, August 17, 2016 5:28 PM