错误System.ArgumentException不支持关键字。 C ++

时间:2017-05-08 19:08:57

标签: mysql c++-cli

我尝试制作连接MySQL数据库并更改其中信息的程序。但是当我尝试插入一些命令时,我会收到错误。

System.Data.dll中类型为“System.ArgumentException”的未处理异常 附加信息:不支持关键字。

namespace Pro4 {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace MySql::Data::MySqlClient;

/// <summary>
/// Сводка для MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
    MyForm(void)
    {
        InitializeComponent();
        //
        //TODO: добавьте код конструктора
        //
    }

protected:
    /// <summary>
    /// Освободить все используемые ресурсы.
    /// </summary>
    ~MyForm()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::TextBox^  txtQuery;
protected:

protected:
private: System::Windows::Forms::Button^  button1;

private:
    /// <summary>
    /// Требуется переменная конструктора.
    /// </summary>
    System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
    /// <summary>
    /// Обязательный метод для поддержки конструктора - не изменяйте
    /// содержимое данного метода при помощи редактора кода.
    /// </summary>
    void InitializeComponent(void)
    {
        this->txtQuery = (gcnew System::Windows::Forms::TextBox());
        this->button1 = (gcnew System::Windows::Forms::Button());
        this->SuspendLayout();
        // 
        // txtQuery
        // 
        this->txtQuery->Location = System::Drawing::Point(12, 12);
        this->txtQuery->Multiline = true;
        this->txtQuery->Name = L"txtQuery";
        this->txtQuery->Size = System::Drawing::Size(823, 269);
        this->txtQuery->TabIndex = 0;
        // 
        // button1
        // 
        this->button1->Location = System::Drawing::Point(715, 287);
        this->button1->Name = L"button1";
        this->button1->Size = System::Drawing::Size(120, 40);
        this->button1->TabIndex = 1;
        this->button1->Text = L"Run";
        this->button1->UseVisualStyleBackColor = true;
        this->button1->Click += gcnew System::EventHandler(this, 
&MyForm::button1_Click);
        // 
        // MyForm
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(847, 531);
        this->Controls->Add(this->button1);
        this->Controls->Add(this->txtQuery);
        this->Name = L"MyForm";
        this->Text = L"MyForm";
        this->ResumeLayout(false);
        this->PerformLayout();

    }
#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    String^ SQLQuery = txtQuery->Text;
    String^ connectionInfo = "datasourse=localhost;port=3307;username=root;password=1qa2ws3ed;database=labeng";
    MySqlConnection^ conn= gcnew MySqlConnection(connectionInfo);
    MySqlCommand^ connCmd = gcnew MySqlCommand(SQLQuery, conn);
    MySqlDataReader^ dataReader;

    try{
        conn->Open();
        dataReader = connCmd->ExecuteReader();
        //MessageBox::Show("Command is done");
    }
    catch (Exception^ex){
        MessageBox::Show(ex->Message);
    }

}
};
}

请不要严格,这对我来说是新的。

1 个答案:

答案 0 :(得分:0)

标准警告:虽然可以在C ++ / CLI中编写应用程序的主体,甚至使用WinForms在C ++ / CLI中编写GUI,但不建议这样做。 C ++ / CLI适用于互操作场景:C#或其他.Net代码需要与非托管C ++接口,C ++ / CLI可以提供两者之间的转换。对于主要开发,如果您需要托管代码,建议使用带有WinForms或WPF的C#,如果您想要不受管理,建议使用带有MFC的C ++。

那就是说,

String^ connectionInfo = "datasourse=localhost;port=3307;username=root;password=1qa2ws3ed;database=labeng";

根据documentation,连接字符串应包含server=localhost,而不是datasource=localhost