com/2006/01/ms-access-application-with-c/
About
C# Articles
.NET Articles
C# Tools
Forum
What lead me to write this application is when i wanted to access theMSAccess database
using c sharp I couldn't get any informationmaterial. All the material available on the net is
partial to sql, andhence the purposewe will develop this application in 2 phase First we will
see how tomake the database connection to the MSAccess and see what theintricacies of it.
And then we will finish with the application.
Enough of the talking and let us move towards the main topic.The connection to the
database is rather modified as compared with the ADO connection that we had earlier. The
following figure shows the sequence properly (i hope)
OleDbConnection–> OleDbCommand –> OleDbDataReader
nowthose who are familiar with ado will obiviously recognise thesimillarity but for some
clarification and for those who are not wellversed with ado here is little explanation.
OleDbConnection –> represents singleconnection to the database, and depending upon the
capabilites of theunderlying database it gives you the power to manipulate the database.The
point to remember here is even though oledbconnection object goesout of scope it does not
get closed. And therefore you will have toexplicitely call the close() method of the object.
OleDbCommand –> this is our normal commandobject as we had in ado. You can call sql
stored procedures and sqlqueries through this object.
OleDbDataReader –> Now this class is ofparamount importance since it gives actual access
1 of 5 2/13/2011 11:43 PM
MS Access Application With C# | C# Help – C# Tutorials and Resources http://www.csharphelp.com/2006/01/ms-access-application-with-c/
to the underlyingdataset of the database. Once you call the ExecuteReader method of
theOleDbCommand it gets created the dotnet beta 2 sdk says not to createthe object of this
class directly.
Now you can see more about these main object in .net beta 2 documentation and here is the
source code of how to make the program access the database.
using System;
using System.Data.OleDb;
class OleDbTest{
2 of 5 2/13/2011 11:43 PM
MS Access Application With C# | C# Help – C# Tutorials and Resources http://www.csharphelp.com/2006/01/ms-access-application-with-c/
Now lets talk about various details of what wehave learnedin the constructor of the oledbconnection you have
seen "provider="stuff. there are following types of drivers which are compatible withado.net.
sqlolddb –> Microsoft OLE DB Provider for SQL Server,
msdaora –> Microsoft OLE DB Provider for Oracle,
Microsoft.Jet.OLEDB.4.0 –> OLE DB Provider for Microsoft Jet
you can choose any of then but they will demand different parameters tobe passed to then for example the
jet.oledb.. needs the name of the mdbfile and sqloledb need the name of the user and its password.
These all drivers are located inSystem.Data.OleDb namespace and hence you must include it, again theyare not
compatible with oledb provider for odbc. i.e. you can't usethese drivers and try to access database thru you vb6.0
application sodon't go finding the references of these files in c:
Following guidelines are given by Microsoft while choosing the providersSQL Server:
.NET Data Provider Recommended for middle-tier applications using Microsoft SQL Server 7.0 or Later.
Recommended for single-tier applications using Microsoft Data Engine (MSDE) or Microsoft SQL Server 7.0
orlater.
Recommended over use of the OLE DB Provider for SQL Server (SQLOLEDB) with the OLE DB .NET Data
Provider.
For Microsoft SQL Server 6.5 and earlier, you must use the OLE DB Provider for SQL Server with the OLE
DB.NET Data Provider.
OLE DB .NET Data Provider Recommended for middle-tier applications using Microsoft SQL Server 6.5 or
earlier, or Oracle.
For Microsoft SQL Server 7.0 or later, the SQL Server .NET Data Provider is recommended.
Recommended for single-tier applications using Microsoft Access databases.
Use of the OLE DB .NET Data Provider with a Microsoft Access database for a middle-tier application is
notrecommended.
Support for the OLE DB Provider for ODBC (MSDASQL) is disabled.
I think i will stop for now and will continue in the (may be) next session the details of the dotnet Please let me
know if code does not run, if it runs
Share
Data Access
Create An Editor Using C#
Introduction to C# Windows Form Component Layout
Leave a Reply
3 of 5 2/13/2011 11:43 PM
MS Access Application With C# | C# Help – C# Tutorials and Resources http://www.csharphelp.com/2006/01/ms-access-application-with-c/
Submit Comment
Database for .NET
Store .NET objects directly without OR
mapping and boost performance.
www.versant.com/
Popular
Latest
Comments
Tags
4 of 5 2/13/2011 11:43 PM
MS Access Application With C# | C# Help – C# Tutorials and Resources http://www.csharphelp.com/2006/01/ms-access-application-with-c/
Useful Sites
ASP.NET Hosting
Cloud Hosting Magazine
LightSwitch Tutorial
PHP MySQL Tutorial
SharePoint Tutorial
SQL Server Performance
Windows / SQL Azure Tutorial
Windows Phone Pro- Developers
Windows Server Help
5 of 5 2/13/2011 11:43 PM