using System.Data.Odbc;
string MyConString = "DRIVER={MySQL ODBC 5.2w Driver};" +
"SERVER=localhost;" +
\
"DATABASE=mysql;" +
"UID=root;" +
"PASSWORD=password;" +
"OPTION=3";
//使用Connector/ODBC连接到MySQL
OdbcConnection MyConnection = new OdbcConnection(MyConString);
//打开连接
MyConnection.Open();
OdbcCommand oCmd = new OdbcCommand("select * from user", MyConnection);
OdbcDataAdapter oDa = new OdbcDataAdapter(oCmd);
DataSet oDs = new DataSet();
oDa.Fill(oDs, "username");
// MessageBox.Show(oDs.Tables[0].Rows[0].ItemArray.Length.ToString());
dataGridView1.DataSource = oDs.Tables["username"];
//MessageBox.Show("\n !!! success, connected successfully !!!\n");
MyConnection.Close();