Use mysqldrivercs to connect to the MySQL database
Download and install mysqldrivercs first. Address:
Http://sourceforge.net/projects/mysqldrivercs/
Find mysqldriver. dll in the installation folder, and add the mysqldriver. DLL to the project.
Note: the version I downloaded is a MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. Data. ODBC;
Using system. drawing;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Using mysqldrivercs;
Namespace MySQL
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Private void form1_load (Object sender, eventargs E)
{
Mysqlconnection conn = NULL;
Conn = new mysqlconnection (New mysqlconnectionstring ("localhost", "CRM", "root", "QAZ"). asstring );
Conn. open ();
// The following two lines are very important. Otherwise, Chinese characters are garbled.
Mysqlcommand commn = new mysqlcommand ("set names gb2312", Conn );
Commn. executenonquery ();
String SQL = "select * from exchange ";
Mysqldataadapter MDA = new mysqldataadapter (SQL, Conn );
Dataset DS = new dataset ();
MDA. Fill (DS, "Table1 ");
Datagridview1.datasource = Ds. Tables ["Table1"];
Conn. Close ();
}
}
}