C# Connectivity with MYSQL using ODBC

First of all Downlaod MyODBC-3.51.06.exe and install.

Now add the following lines of code to connect it to the DataBase.
string sConString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE=Lakhan; UID=root; PASSWORD=; OPTION=3";
OdbcConnection oConnection = new OdbcConnection(sConString);
string sSQL = "SELECT * FROM tdTest";
OdbcDataAdapter oDataAdapter = new OdbcDataAdapter(sSQL, oConnection);
DataSet oDataSet = new DataSet();
oDataAdapter.Fill(oDataSet);
This piece of code will return a DataSet that contains data from tdTest Table.

0 comments: