C# 连接MySQL

    技术2022-05-20  33

          用MySQLDriverCS连接MySQL数据库 :

          C#用MySQLDriverCS连接MySql需要两个库文件:libmySQL.dll  MySQLDriverCS.DLL,然后在项目中添加引用  MySQLDriverCS.DLL,再在程序中添加using MySQLDriverCS;然后就进行MySql操作了,如下操作:

     

       MySQLConnection conn = null;

       conn = new MySQLConnection(new MySQLConnectionString("localhost", "Menu","root", "123").AsString);

       conn.Open();

       MySQLCommand comm = new MySQLCommand("set names gb2312", conn);

       comm .ExecuteNonQuery();

       string sql = "select * from table_level ";

       MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);

       DataSet ds = new DataSet();

       mda.Fill(ds, "table1");

       this.dataGridView1.DataSource = ds.Tables["table1"];

       conn.Close();


    最新回复(0)