Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    csharp
  » MySQL and .NET - Using MySQLDriverCS
      by sde
 Page 1 of 1 
   

(Login to remove green text ads)
As of now (Feb 2004), there are a couple different free MySQL APIs for .NET. I have tested both MySQLDriverCS and ByteFX.Data. MySQLDriverCS ( http://sourceforge.net/projects/mysqldrivercs/ ) performed much faster so I will show you how to use it here.

First download the driver from the link above.

You will need to add a reference to MySQLDriverCS in your Solution Explorer. To do this, Right Click on References in your Solution Explorer and choose Add Reference. Click Browse and locate the MySQLDriverCS dll and Click Select. Then Click OK.

The next step is to include the MySQLDriverCS namespace in the code.
Code:
using MySQLDriverCS;
For the most part, MySQLDriverCS mirrors the MSSQL and ODBC methods of database interaction. Below is an example of using MySQLReader to read through query results.
Code:
try { MySQLConnection con; con = new MySQLConnection( new MySQLConnectionString("localhost", "database", "user", "pass").AsString ); con.Open(); string sql = "SELECT * FROM Table"; MySQLCommand cmd = new MySQLCommand(sql,con); MySQLDataReader reader = cmd.ExecuteReaderEx(); while(reader.Read()) { Console.WriteLine( reader[0].ToString() ); } reader.Close(); con.Close(); } catch(Exception ee) { Console.WriteLine( ee.ToString() ); }





 
 Page 1 of 1 
   

Rate This Article
1 2 3 4 5 6 7 8 9 10





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle