2017-05-08 156 views
1

私は自分のMySQLデータベースに接続して情報を変更しようとしました。しかし、私はいくつかのコマンドを挿入しようとするとエラーが発生します。エラーSystem.ArgumentExceptionキーワードがサポートされていません。 C++

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); 
    } 

} 
}; 
} 

私には厳しいものではありません。

+0

今後、すべてのGUIコードを質問にダンプしないでください。例外をスローしている行は正確に記述してください。私たちに検索や推測をさせてはいけません。あなたのコード全体を検索して、面白いビットを見つけたり、どのラインが例外を出すのかを推測してください。 –

答えて

0

標準的な警告:アプリケーションの本体をC++/CLIで記述したり、WinFormsを使用してC++/CLIでGUIを記述することは可能ですが、推奨されません。 C++/CLIは相互運用シナリオを対象としています:C#やその他の.NetコードとアンマネージC++とのインタフェースが必要な場合、C++/CLIはこれらの間の変換を提供します。一次開発では、マネージコードが必要な場合はWinFormsまたはWPFでC#を使用するか、アンマネージを必要とする場合はMFCでC++を使用することをお勧めします。 documentationによると

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

、言っ


、接続文字列はserver=localhost、ないdatasource=localhostを含むようになっています。

+0

ありがとうございました、あなたの警告についての :ありがとう、私はこの次回に従います –

関連する問題