473,699 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1969
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.Connecti onString =
@"Provider=Micr osoft.Jet.OLEDB .4.0;Data
Source=c:\inetp ub\wwwroot\stud ydotnet\study.m db";

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********@lyc os.de> wrote in message
news:78******** *************** ***********@mic rosoft.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******** *******@TK2MSFT NGP11.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.Connecti onString =
@"Provider=Micr osoft.Jet.OLEDB .4.0;Data
Source=c:\inetp ub\wwwroot\stud ydotnet\study.m db";

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********@lyc os.de> wrote in message
news:78******** *************** ***********@mic rosoft.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=Micro soft.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(st rSelect, objConnect);

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

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

DataGrid1.DataS ource =
objDataReader;
DataGrid1.DataB ind();

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

//close the DataReader and
Connection
objDataReader.C lose();
objConnect.Clos e();

}

catch (Exception objError)
{

//display error details
outError.InnerH tml = "<b>*
Error while accessing data</b>.<br />"
+ objError.Messag e
+ "<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
12112
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). It has worked relatively well for some time, but recently I'm often encountering errors when trying to fetch the data. I am pretty sure that this is because of a poor wireless connection since I'm also having some problems e.g. copying files...
1
5525
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 table of the MS-SQL Database, "TestODBC". I wanted to use StoredProcedure1 as the bound recordsource for a new form Form1. But I
18
2640
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 and the error. Any help please. Connection: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=http://n.1asphost.com/WStoreyII/PIMP.mdb" Error: Microsoft JET Database Engine (0x80004005) Not a valid file name. /Default.asp, line 40
14
3498
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, one developer suggested that it's a security flaw; therefore connection strings should be kept somewhere else or encrypted. My argument is that web.config file is protected by IIS and Windows security which is the case. And another argument is that...
35
4835
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 string in the web.config. I created a class with a static database connection and the class opens and closes the database.
8
9630
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 work from
20
3282
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 many connection has been used ? 2. If the maximum pool size has been reached, what happens when I call the method Open to open the connection ? Will I get an error ? MSDN says the request is queued, but will I get an error in the open method ? ...
2
3261
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 or Access database as following : It will connect first to the Master database (SQL or Access, connection String of this database should be read from the C:\WINDOWS
6
8161
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 server mobile ce database. Until recently I was synching everything thru a com port serial cable. The devices would connect to the computer thru activesync and are able to acquire an internet connection. The sync for the program occurs thru a website...
9
6275
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 only has read access to the users table so that users can log in. Once a user has been logged in successfully I want to escalate that user's access level to one appropriate to their role, which will include switching the postgres user they are...
0
8686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9173
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9033
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8911
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6533
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.