Now that we know some of the classes we’ll be working with we need to be able to access them from our web page. We do this by importing the namespace at the top of our page.
If we didn’t import the namespace we’d obviously get an error when we tried to use the classes and create objects.
Next we need to think about creating a connection object that will allow us to connect to our MS Access database. We’ll declare an OledbConnection variable that’s fit for the purpose of holding a connection object.
‘Dim Connection As String’ obviously wouldn’t suffice, as we need a variable that can specifically store a connection object.
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’.
If we didn’t pass in a connection string then the connection object wouldn’t know where to look.
We can now open the connection object.
<< Reading Records with ASP.NET Part 1 |
Reading Records with ASP.NET Part 3 >> |
Get the best asp web hosting provider now and save 30%
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.