gpt4 book ai didi

mysql - VC++连接mysql关于Connection和Sql String

转载 作者:行者123 更新时间:2023-11-29 22:47:55 25 4
gpt4 key购买 nike

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

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”中。怎么做?

谢谢!

最佳答案

看起来和C++一点关系都没有。您是否尝试过 docs 中的“数据库”参数?:

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

关于mysql - VC++连接mysql关于Connection和Sql String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29014581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com