473,382 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Connection to a MS Access database

How to get connection to a MS Access database?
How to read from a MS Access database?
How to close the connection to a MS Access database?
Nov 16 '05 #1
4 1957
Hi

Accessing an Access database is just as easy as accessing any other
database. You should use OleDb data providers to establish a connection. A
connection string is something like this. The Provider is the most important
thing to remember. Note, that the database must exist.

dbconn.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\inetpub\wwwroot\studydotnet\study.mdb";

You can read data just as easily as with any other datasource. You can use a
DataAdapter to fill a DataSet, or use the DataReader to read data. In either
case, you can use SQL SELECT statement to get the data.

And closing, well, simply call Close() on the connection. It really doesn't
work that much different from other data providers.

-Artur
"Eifel-benz" <Ei********@lycos.de> wrote in message
news:78**********************************@microsof t.com...
How to get connection to a MS Access database?
How to read from a MS Access database?
How to close the connection to a MS Access database?

Nov 16 '05 #2
Just for info, in case you hadn't seen it if you can't remember a connection
string you can always visit http://www.connectionstrings.com/ which should
help.

Ross.

"Artur Sorszegi" <ar***********@freemail.hu> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi

Accessing an Access database is just as easy as accessing any other
database. You should use OleDb data providers to establish a connection. A
connection string is something like this. The Provider is the most important thing to remember. Note, that the database must exist.

dbconn.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\inetpub\wwwroot\studydotnet\study.mdb";

You can read data just as easily as with any other datasource. You can use a DataAdapter to fill a DataSet, or use the DataReader to read data. In either case, you can use SQL SELECT statement to get the data.

And closing, well, simply call Close() on the connection. It really doesn't work that much different from other data providers.

-Artur
"Eifel-benz" <Ei********@lycos.de> wrote in message
news:78**********************************@microsof t.com...
How to get connection to a MS Access database?
How to read from a MS Access database?
How to close the connection to a MS Access database?


Nov 16 '05 #3
Hi,

Here's the code

string strConnect
= "Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source="+Server.MapPath(".\\db\\forum.mdb");
string strSelect = "SELECT * FROM
topics ORDER BY TopicCreateDate DESC";
try
{

//create a new
OleDbConnection object using the connection string
OleDbConnection objConnect
= new OleDbConnection(strConnect);

//open the connection to
the database
objConnect.Open();

//create a new
OleDbCommand using the connection object and select
statement
OleDbCommand objCommand =
new OleDbCommand(strSelect, objConnect);

//declare a variable to
hold a DataReader object
OleDbDataReader
objDataReader;

//execute the SQL
statement against the command to fill the DataReader
objDataReader =
objCommand.ExecuteReader();

DataGrid1.DataSource =
objDataReader;
DataGrid1.DataBind();

if (DataGrid1.Items.Count
== 0)
{
outError.InnerHtml
= "There are currently no Postings for this topic, start
the posts with the form above.";
}

//close the DataReader and
Connection
objDataReader.Close();
objConnect.Close();

}

catch (Exception objError)
{

//display error details
outError.InnerHtml = "<b>*
Error while accessing data</b>.<br />"
+ objError.Message
+ "<br />" + objError.Source;
return; //and stop
execution
}

Irfan
Nov 16 '05 #4
Sorry, seems to be self explainatory!. it shows the usage
of a datagrid control and how the data from db is attached
to it.
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Peter Larsson | last post by:
Hi there, I've recently developed a VBA-program in Excel that fetches and presents data from a distant Access database over a wireless peer-to-peer network (both computers running Win XP Pro)....
1
by: Lyle Fairfield | last post by:
I created a new MS-SQL Database, "TestODBC". I made Table1 and StoredProcedure1. I made an ODBC DSN for that MS-SQL Database. I created a new AccessXP mdb, "TestODBC". I linked to the...
18
by: WStoreyII | last post by:
I am making a asp page that will run on my computer by iis. But the problem is the database in on a web server. I can not seem to get the connection to work for it though here his the connection...
14
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review,...
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
8
by: Greg Strong | last post by:
Hello All, The short questions are 1 Do you know how to make DSN connection close in Access to Oracle 10g Express Edition? &/or 2 Do you know how to make a DSN-less pass-through query...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
2
by: Orit | last post by:
Hello . Please find below my questions - I hope some of the ASP.NET experts of this forum will answer to those beginner's questions : My Web site should be able to work with either SQL Server...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.