Categories

Tools

bitdefender

1&1 Web Hosting

Enter the data, programmatically, from an Access database table in a ASP.NET GridView


Suppose we have the Northwind.mdb Access database stored in the App_Data folder, and we want to display some data in a GridView.

Code:

<div>
	<asp:GridView ID="GridViewEmployees" runat="server" 
		CellPadding="4" 
		ForeColor="#333333" 
		GridLines="None" 
		Width="500">
		<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
		<EditRowStyle HorizontalAlign="Left" />
		<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
		<RowStyle BackColor="#F7F6F3" ForeColor="#333333"/>
	</asp:GridView>
</div>

In the code-behind file that you can write code like this.

Code:

AccessDataSource ads = new AccessDataSource();

string dataFile = Server.MapPath("~/App_Data/Northwind.mdb");

string selectCommand = "SELECT Employees.TitleOfCourtesy AS Title, Employees.LastName AS Surname, Employees.FirstName  AS Name, Employees.City " +
						"FROM Employees " +
						"ORDER BY Employees.LastName";

ads.DataFile = dataFile;
ads.SelectCommand = selectCommand;

GridViewEmployees.DataSource = ads;
GridViewEmployees.DataBind();

Here is what displays the GridView:

Enter the data, programmatically, from an Access database table in a ASP.NET GridView

Posted in ASP.NET by MdmSoft

If our work has been of help, you can help us with a small donation...
Our programmers will thank you!



All information contained in this web site are the property of MdmSoft. The information is provided "as is", MdmSoft will not be liable for any misuse of the code contained in these pages, nor can it be for inaccuracies, grammatical errors or other factors that may have caused damage or lost earnings. MdmSoft is not responsible for the content of comments posted by users.
The examples in this area have the educational and demonstration purposes only, and may be copied only for your reference, but cannot be used for commercial purposes, or for any other purpose, without the express written consent of MdmSoft.
MdmSoft also reserves the right to change, without notice, to your liking this web site, the pages and its sections, and may suspend temporarily or definitely the various services included on this site.
While using this site, you agree to have read and accepted our Terms of Service and Privacy Policy.