Database
  Home arrow Database arrow Database Programming in C# with MySQL : Us...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Database Programming in C# with MySQL : Using OleDB
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 33
    2007-06-18

    Table of Contents:
  • Database Programming in C# with MySQL : Using OleDB
  • OleDB continued
  • Accessing MySQL, Step by Step
  • MySQL Access in the Real World

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database Programming in C# with MySQL : Using OleDB


    (Page 1 of 4 )

    Persisting the data processed by an application has become the norm. The data can be stored either in a file system using normal files or in databases. The functionalities provided by database packages make them a more attractive proposition. With the advent of open source database products such as MySQL, the use of databases for data persistence has become more or less ubiquitous. Hence, no language or platform can ignore the need to provide libraries to access databases, especially MySQL, and .Net as a platform and C# as a language are no exceptions.

    There are three main Data Providers, as the database access APIs are known in .Net, which are the SQL Data Provider, the OleDB Data Provider and the ODBC Data Provider. Of these I will be focusing on the OleDB Data Provider and using it to work with a MySQL database. The first and second sections of this article will provide insight into the various APIs that form the OleDB. The third section will detail the steps required to access MySQL using OleDB. In the last section, I will develop a real-world application that implements the theory provided in the first three sections. That's the outline for this discussion.

    OleDB: What is it?

    OleDB is one of the three Data Providers supported by .Net. It is part of the System.Data namespace; specifically, all the classes of OleDB come under the System.Data.OleDb namespace. OleDB had been around before .Net came into the picture. The OleDB Provider provides a mechanism for accessing the OleDB data source (databases that could be connected through OleDB) in the managed space of .Net. In essence, the OleDB Data Provider sits between a .Net-based application and OleDB. The main classes that form the OleDB Data Provider are:

    1. OleDbConnection
    2. OleDbCommand
    3. OleDbDataAdapter
    4. OleDbDataReader

    Most of the classes are arranged in a hierarchical manner, that is, one provides an instance of the other. For example, OleDbCommand provides an instance of OleDbDataReader.

    OleDbConnection represents a connection with a data source such as a database server. Each connection represented by OleDbConnection's instance is unique. When an instance of OleDbConnection is created, all its attributes are given or set to their default values. If the underlying OleDB Provider doesn't support certain properties or methods, the corresponding properties and methods of OleDbConnection will be disabled. To create an instance of OleDbConnection, its constructor has to be called with a connection string. The connection string specifies the parameters needed to connect with the data source. The following statement shows an example of this:

    OleDbConnection conn = new OleDbConnection(
         "Provider=MySqlProv;" +
         "Data Source=localhost;" + 
         "User id=UserName;" + 
         "Password=Secret;"
    );

    The above example provides a connection to MySQL server at local machine.

    OleDbCommand represents a command to be executed against a data source connected through an OleDbConnection instance. In the context of databases the command can be a SQL statement or a stored procedure. To get an instance of OleDbCommand, its constructor has to be called with an instance of the OleDbConnection class and the string containing the SQL query to be executed. For example, the following statement creates an instance of an OleDbCommand named command:

    string queryString = "SELECT OrderID, CustomerID FROM Orders";
    OleDbCommand command = new OleDbCommand(queryString, conn);

    More Database Articles
    More By A.P.Rajshekhar


       · In this article I have discussed about using OleDB Data Provider to access MySQL...
       · But in this Article i m getting this error"The 'MySqlProv' provider is not...
       · Nice described in the article. Keep going on!If you would have used ODBC instead...
       · me too getting the same error. some one please let me know the cause for this?
       · Why is the verb "store" not acceptable? "Persist" is an intransitive verb, and...
     

    DATABASE ARTICLES

    - Building Applications with Anonymous Types
    - A Closer Look at Anonymous Types
    - Programming with Anonymous Types
    - Converting Your Excel Worksheet into a Worki...
    - Excel Reference
    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek