No of visitors who read this post:
420
Category:
.NET Programming
Type:
Question
Author:
Timothy Ward
Hi,
I am working on an ASP.NET shopping cart application using Microsoft Visual Web Developer Express 2005. Right now, I am having problems getting a specific file to connect the applications pages to the databases to store the product information and the shopping cart state.
I need someone to help me know how I can connect this databases to my applications pages. I'm a newbie in this kind of work, but I have plenty of time to play with it. I am willing to learn new tricks on how to make this work.
Any help would be greatly appreciated!
Thanks.
- Login or Signup Now to post comments

You can use ADO.Net or LINQ for connecting your web application to the database. If you want to connect to the database using the data source control, follow the steps below:
The Providers
The ADO.NET or ActiveX Data Object for .NET is a class that a programmer uses to communicate with data services and data. For some provider it might able to connect with Oracle database. Here is the list of providers that is included with .NET:
The Connection String
It is used by the provider to communicate to the database. You can place connection strings under the Web.config file and define data source controls configuration entries.
Here is the actual code sample in connecting Web application to the database (Access database)
For the declaration, remove the quotation marks:
"<%@ Import Namespace="System.Data" %>"
"<%@ Import Namespace="System.Data.OleDb" %>"
For the connection string:
Dim Conn as OleDbConnection
Conn= New OleDbConnection("PROVIDER=Microsoft.Jet.OlEDB.4.0;" + "Data Source=" + Server.MapPath("MyDatabase.mdb"))
For insert command:
Insertdata = New OleDbCommand(“Insert into “tablename” (“Fields”) Values (“Data Fields”)”, Conn)
For retrieving:
Dim FindItem as OleDbCommand
finditem = New OleDbCommand (“SELECT (fieldnames) from (tablename) WHERE Field=!Field”, Conn)
Study the code above, you should be able to figure out how to connect your application to the database.
Connecting to a database in ASP.Net has many ways. The most common techniques are Linq and ADO.NET. The example below will discuss how to connect to a database using ADO.NET. I chose this technique because it is compatible with visual studio 2005 – 2008 – 2010.
Developer started to use LINQ, when visual studio 2008 is published. So if you use, for example Visual Studio 2005, you cannot use LINQ technique. ADO.Net deals with database in two ways: online and offline. The offline mode is used when you have to do some operations on the retrieved data and repost these data to the database. The online technique is to deal with data in the same time.
http://msdn.microsoft.com/en-us/library/ms178371.aspx
I hope that it helps you.
Regards,
John