0
Thanks

A few words of thanks would be greatly appreciated.

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

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.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team

Published by . Latest update on 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 (https://ccm.net/).

0 Comments