MySQL ODBC Driver

  • Thread starter Thread starter Greg Smith
  • Start date Start date
G

Greg Smith

I just got a project accessing MySQL. How can I can find the ODBC driver
for it?

Are there other ways of connecting to it from C#?


Any help is greatly appreciated.
 
Hi Greg,

There are several .net providers that you can use for MySql that are free.
I tend to think that you will have better performance using these providers
instead of going through ODBC (although I do not have any hard metrics on
this). I have posted a couple of the urls below for you to look at. There
are plenty more if you do a web search for it. If all else fails you can use
the OleDb classes.

I hope this helps.
 
Hi Greg Smith

First you need to install ODBC .Net Data Provider. See downloads section of
C# Corner. After that you must install MyODBC (ODBC driver for MySQL from
http://www.mysql.com). I'm assuming that you're already running MySql server
with no problems.

ODBC .Net data provider provides classes similar to OleDb and Sql data
providers. For example, OdbcConnection, OdbcDataAdapter, OdbcCommand,
OdbcTransaction, OdbcParameter etc are some ODBC .Net data provider classes.

ODBC .Net data provider is defined in the Microsoft.Data.Odbc namespace. You
must add reference to this namespace and import it in your application.

protected void Page_Load(Object sender, EventArgs e)
{
string mySQLConnStr = "driver={MySQL};";
mySQLConnStr = mySQLConnStr + "server=10.54.19.150;";
mySQLConnStr = mySQLConnStr + "uid=root;";
mySQLConnStr = mySQLConnStr + "pwd=xxxxxxxx;";
mySQLConnStr = mySQLConnStr + "database=mysql;";
mySQLConnStr = mySQLConnStr + "OPTION=17923";
/* Above is option 1, 2, 512, 1024, 16384 see mySQL
manual for details. But the key is 512 Pad char
fields to full length.
*/
OdbcConnection myConnection = new OdbcConnection
(mySQLConnStr);
string SQL = "select * from user";
OdbcDataAdapter myCommand = new OdbcDataAdapter(SQL,
myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "user");
MyDataGrid.DataSource=ds.Tables["user"].DefaultView;
MyDataGrid.DataBind();
}
 
Back
Top