LogoASPAlliance: Articles, reviews, and samples for .NET Developers
CodeSnip: Fill a DataGrid From an Access Database
by Web Team at ORCS Web
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 10662/ 13

The code below demonstrates how to connect to and query a Microsoft Access database and then bind those results to an ASP.NET datagrid for display as an HTML table.

<%@ Page language="VB" Debug="false" %> 
<%@ Import Namespace="System.Data" %> 
<%@ Import Namespace="System.Data.OleDb" %> 
<script language="VB" runat="server"> 
Sub Page_Load(Sender as Object, E as EventArgs) 
  Dim oConn As OleDbConnection 
  Dim oComm As OleDbDataAdapter 
  Dim sConn As String 
  Dim sComm As String 
  Dim oDataSet As New DataSet 

  'Build the connection string 
  sConn = "Provider=Microsoft.Jet.OLEDB.4.0;" 
  sConn += "Data Source=C:\Inetpub\wwwroot\Sample\grocertogo.mdb;" 
  sConn += "Persist Security Info=False" 

  'Build the SQL string sComm = "SELECT Products.ProductID, " 
  sComm += "Products.ProductName, " 
  sComm += "Products.ProductDescription, " 
  sComm += "Products.UnitPrice " 
  sComm += "FROM Products" 

  'Usually you would use error-handling here. It is left out to 
  'make the code as simple as possible. 

  'Create the connection and command objects 
  oConn = New OleDbConnection(sConn) 
  oComm = New OleDbDataAdapter(sComm, oConn) 

  'Fill the dataset with the results of the query 
  oComm.Fill(oDataSet, "Products") 

  'Set the grid source to the dataset and bind the data 
End Sub 

<title>Fill A DataGrid From Access Database</title> 
  <asp:DataGrid id="oGrid" runat="server" /> 

by Brad Kingsley the Founder and President of ORCS Web, Inc. - a company that provides managed hosting services for clients who develop and deploy their applications on Microsoft Windows platforms.

Product Spotlight
Product Spotlight 

©Copyright 1998-2021  |  Page Processed at 2021-02-24 9:52:49 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search