gpt4 book ai didi

c++ - 不允许使用非托管类的句柄

转载 作者:行者123 更新时间:2023-11-28 04:46:11 25 4
gpt4 key购买 nike

我正在尝试在 C++ Windows 窗体和 mysql 数据库之间建立连接,但它向我显示了这个错误。

a handle to a non-managed class is not allowed

        #pragma endregion
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
std::string^ constring =L "datasource=localhost;port=**;username=root;password=**";
MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);
MySqlCommand^ cmdDataBase=gcnew MySqlCommand("",conDataBase);
}
};
}

最佳答案

std::string 是 C++ 标准库中的字符串类。您不能将它与 ^ 一起使用(即,作为托管类)。

改为使用 .NET String 类:

System::String^ constring = L"datasource=localhost;port=**;username=root;password=**";

关于c++ - 不允许使用非托管类的句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49215845/

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