ASP.NET application pages doesn’t connect to the databases

Asked By 200 points N/A Posted on -
qa-featured

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.

SHARE
Best Answer by Jerry Maguire
Best Answer
Best Answer
Answered By 0 points N/A #113164

ASP.NET application pages doesn’t connect to the databases

qa-featured

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:
You must first determine the data source control type that you will need. If you use LinqDataSource this allows you to use syntax (LINQ) to access the data from the data source. The ObjectDataSource is used to retrieve the data as well as modify it. SqlDataSource, lets you provide a data source connection and SQL statement in retrieving and modifying the data.
When you use LINQ control, the database and tables is represented by the classes that you need to create. For further analysis, visit this link:
If SqlDataSource control is used you must specify the provider that you will use. The default provider is the SystemDataSqlClient.
Set the data access properties after adding the data source control to the page. If you use the ObjectDatasource to modify the data it requires one or more methods and an object middle-tier business. The SqlDataSource to modify the data it requires a connection string. The LinqDataSource to access the data it requires a class for the database and the table. EntityDataSource, for a specific database it also requires a connection string to access the data.
You can set as individual properties for the specified provider and connection of SqlDataSource or have it defined globally in the Web.config file of the application.

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:
If you connect directly to the default provider which is the SqlDataSource you don’t need to explicitly specify data provider.
The OLE DB data provider (System.Data.OleDb)
The ODBC data provider (System.Data,Odbc)
The Oracle data provider (System.Data.OracleClient)

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.

Answered By 0 points N/A #113165

ASP.NET application pages doesn’t connect to the databases

qa-featured

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 choose 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

Login/Register to Answer

Related Questions