Searching Records in a Microsoft Access Database with ASP.NET - Part 1

The 4 previous examples we have used Reading records from an Access Database, Inserting Records into an Access Database, Updating Records and Deleting Records have been very simple and straightforward and haven’t allowed for any real degree of user interaction.

Our search example code below is very similar to the Reading Records example though the records returned are filtered depending on the text entered into the textbox ‘textbox1’. When the user clicks the button ‘btnSubmit’ the click event of the button is raised and the associated subroutine ‘SearchRecords’ is executed returning the appropriate records.

Though we’ve covered most of the initial code in our Read Records example we’ll go through it again for learning purposes.

First of all we need to import the System.Data.Oledb namespace. Importing this namespace into our page allows us to access the Connection, Command and DataReader classes that we need to perform some of our database tasks.

<%@ Import Namespace="System.Data.Oledb" %>

Next we need to think about creating a connection object that will allow us to connect to our MS Access Database ‘Customers.mdb’. Declare an OledbConnection variable that’s fit for the purpose of holding a connection object.

Dim Connection As OledbConnection

After declaring the connection variable we need to create a connection object. We do this using the New Keyword and at the same time we pass in a parameter i.e. the connection string to our newly created connection object. The connection string will hold the provider name that in our case is Microsoft.jet.Oledb4.0, the file name and path to the database (‘C:\Inetpub\wwwroot\code\Customers.mdb’).

Once we’ve created our connection object we can assign it to our connection variable ‘connection’.

We can now open the connection object.

Connection.Open()

Get the best asp web hosting provider now and save 30%

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.