C#连接MySql数据库的连接字符串是什么?

2024-11-27 18:31:19
推荐回答(1个)
回答1:

using MySQLDriverCS;
// 建立数据库连接MySQLConnection DBConn;DBConn = new MySQLConnection(new MySQLConnectionString("localhost","mysql","root","",3306).AsString);DBConn.Open();
// 执行查询语句MySQLCommand DBComm;DBComm = new MySQLCommand("select Host,User from user",DBConn);
// 读取数据MySQLDataReader DBReader = DBComm.ExecuteReaderEx();
// 显示数据try{while (DBReader.Read()){Console.WriteLine("Host = {0} and User = {1}", DBReader.GetString(0),DBReader.GetString(1));}}finally{DBReader.Close();DBConn.Close();}
//关闭数据库连接DBConn.Close();