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();
}