ASP.NET using C# - How to Connect/Retrieve in database to web a

May 2017

Some people may be carrying out projects in ASP.NET and they may need help with connecting their database with ASP.NET. Likewise with retrieving in database to web application. A specific sequence must be followed with regards to the database and the retrieving process. Some programming knowledge is needed to able to carry out the steps. The answer below should provide the answers to the issues just mentioned.

Issue



I am doing my project work, and I have a problem. My project is in asp.net but I don't know how to connect the database in asp.net using c# and how to retrieve in database to web application.

Solution


Notice this line:
-> database. conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data source= @"path AccessFile.mdb";

It should be:
-> database. conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=AccessFile.mdb";

Other Connection String Sample.

Visual Basic]     
Public Sub CreateSqlConnection()     
Dim myConnection As New SqlConnection()     
myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30"     
myConnection.Open()     
End Sub 'CreateSqlConnection     

[C#]     
public void CreateSqlConnection()     
{     
SqlConnection myConnection = new SqlConnection();     
myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";     
myConnection.Open();     
}     

[C++]     
public:     
void CreateSqlConnection()     
{     
SqlConnection* myConnection = new SqlConnection();     
myConnection->ConnectionString = S"Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";     
myConnection->Open();     
}     

Note


Thanks to Wicket for this tip on the forum.

Related


Published by aakai1056. Latest update on March 10, 2012 at 04:49 PM by Virginia Parsons.
This document, titled "ASP.NET using C# - How to Connect/Retrieve in database to web a," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).