关于Connection和Sql String的VC ++与mysql的连接

时间:2015-03-12 16:00:22

标签: mysql visual-c++

我看过一些示例代码,用于编写与mysql函数的VC ++连接。功能就是工作。

public: String^ url = "localhost";
public: String^ dbName = "dbtest";
public: String^ userName = "root";
public: String^ password = "password";
public: String^ port = "3306";

String^ MysqlUrl = L"datasource=" + url + ";port=" + port + ";username=" + userName + ";password=" + password;
SelectStr = L"SELECT * FROM " + dbName + ".dbtable0001 WHERE id='" + select_id_var + "';";
MySqlConnection^ MysqlConn = gcnew MySqlConnection(MysqlUrl);
MySqlCommand^ MysqlCmd = gcnew MySqlCommand(SelectStr, MysqlConn);

但是我希望“dbName”在“MysqlUrl”中,而不是在“SelectStr”中。怎么做?

谢谢!

1 个答案:

答案 0 :(得分:0)

它似乎根本与C ++无关。您是否尝试过docs中的“数据库”参数?:

String^ MysqlUrl = L"datasource=" + url + 
    ";port=" + port + 
    ";username=" + userName + 
    ";password=" + password + 
    ";database=" + dbName;