ASPNetFAQ.com: What is ASP.NET?

Technology posts on ASP.NET, IIS, Windows (+ a little Linux), Cloud Servers, Hosting, and more!
  • Blog Home
Search the site...

Fill A DataGrid From Access Database

Tweet
Share
0 Shares

Originally posted October 2, 2001 on OrcsWeb.com

The code below demonstrates how to connect to and query a Microsoft Access database 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
  oGrid.DataSource=oDataSet.Tables("Products").DefaultView
  oGrid.DataBind()
End Sub
</script>
<html>
<head>
  <title>Fill A DataGrid From Access Database</title>
</head>
<body>
<asp:DataGrid id="oGrid" runat="server" />
</body>
</html>

More from my site

  • ASP.NET C# and VB web development vs PHPASP.NET C# and VB web development vs PHP
  • Video: Step-by-step ASP.NET MVC Tutorial for BeginnersVideo: Step-by-step ASP.NET MVC Tutorial for Beginners
  • Kendo UI Sample, ASP.NET Ajax Tutorial & MoreKendo UI Sample, ASP.NET Ajax Tutorial & More
  • Change the WordPress Domain Name After Moving a SiteChange the WordPress Domain Name After Moving a Site
  • Redirect from HTTPS to HTTP using an htaccess fileRedirect from HTTPS to HTTP using an htaccess file
Tweet
Share
0 Shares

Comments are closed.

Proverbs 19:20

"Get all the advice and instruction you can, so you will be wise the rest of your life."

A Note On WordPress Hosting

Our main focus is of course .NET, but with a mix of Linux, virtualization, and other technologies. But if you're really looking for the best WordPress hosting specifically, read my WordPress host review to save yourself hassle AND money!




Recent Posts

  • What makes good web hosting?
  • jQuery Mobile C# ASP.NET and N5 Networks Software Repository
  • Open Source Bug Tracking Software and the Orchard Project
  • ASP.NET Development with Dreamweaver MX: Visual QuickPro Guide
  • Kendo UI Sample, ASP.NET Ajax Tutorial & More

Tags

ASP.NET Automation centos CMS css cytanium Development/Coding Email gmail Hosting htaccess http https IIS javascript Learning Linux logparser MySQL nginx openssl OrcsWeb performance PowerShell redirect RHEL security server SherWeb smtp SQL/Databases ssl System Administration telnet terminal tip Troubleshooting Ubuntu virtualization Visual Studio web farm web hosting Windows windows server Wordpress

Categories

  • ASP.net development
  • Development/Coding
  • Hosting
  • IIS (Internet Information Services)
  • SQL/Databases
  • System Administration
  • Virtualization
(c) ASPNETFAQ.com