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
    forums

Go Back   Code Forums > Code Newbie > Submit Tutorials > C#

Reply
 
LinkBack Thread Tools Display Modes
Old 02-23-2004, 07:02 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
MySQL and .NET - Using MySQLDriverCS

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() );
}
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ .NET Resources Kernel_Killer MS Technologies ( ASP, VB, C#, .NET ) 2 09-08-2004 01:57 PM
MySQLDriverCS and VC++.NET milena Platform/API C++ 10 07-21-2004 11:56 AM
Antivirus Concerns in XP and .NET Environments redhead Code Newbie News 1 07-07-2003 02:08 PM


All times are GMT -8. The time now is 02:10 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting