Advertisement
TermSpar

C++ To MySQL

Apr 14th, 2016
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.01 KB | None | 0 0
  1. #pragma once
  2.  
  3. namespace Youtube {
  4.  
  5.     using namespace System;
  6.     using namespace System::ComponentModel;
  7.     using namespace System::Collections;
  8.     using namespace System::Windows::Forms;
  9.     using namespace System::Data;
  10.     using namespace System::Drawing;
  11.     using namespace MySql::Data::MySqlClient;
  12.  
  13.     /// <summary>
  14.     /// Summary for Form1
  15.     /// </summary>
  16.     public ref class Form1 : public System::Windows::Forms::Form
  17.     {
  18.     public:
  19.         Form1(void)
  20.         {
  21.             InitializeComponent();
  22.             //
  23.             //TODO: Add the constructor code here
  24.             //
  25.         }
  26.  
  27.     protected:
  28.         /// <summary>
  29.         /// Clean up any resources being used.
  30.         /// </summary>
  31.         ~Form1()
  32.         {
  33.             if (components)
  34.             {
  35.                 delete components;
  36.             }
  37.         }
  38.     private: System::Windows::Forms::TextBox^  txtQuery;
  39.     protected:
  40.     private: System::Windows::Forms::Button^  button1;
  41.  
  42.     private:
  43.         /// <summary>
  44.         /// Required designer variable.
  45.         /// </summary>
  46.         System::ComponentModel::Container ^components;
  47.  
  48. #pragma region Windows Form Designer generated code
  49.         /// <summary>
  50.         /// Required method for Designer support - do not modify
  51.         /// the contents of this method with the code editor.
  52.         /// </summary>
  53.         void InitializeComponent(void)
  54.         {
  55.             this->txtQuery = (gcnew System::Windows::Forms::TextBox());
  56.             this->button1 = (gcnew System::Windows::Forms::Button());
  57.             this->SuspendLayout();
  58.             //
  59.             // txtQuery
  60.             //
  61.             this->txtQuery->Location = System::Drawing::Point(12, 12);
  62.             this->txtQuery->Multiline = true;
  63.             this->txtQuery->Name = L"txtQuery";
  64.             this->txtQuery->Size = System::Drawing::Size(841, 192);
  65.             this->txtQuery->TabIndex = 0;
  66.             //
  67.             // button1
  68.             //
  69.             this->button1->Location = System::Drawing::Point(741, 210);
  70.             this->button1->Name = L"button1";
  71.             this->button1->Size = System::Drawing::Size(112, 49);
  72.             this->button1->TabIndex = 1;
  73.             this->button1->Text = L"Run";
  74.             this->button1->UseVisualStyleBackColor = true;
  75.             this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
  76.             //
  77.             // Form1
  78.             //
  79.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  80.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  81.             this->ClientSize = System::Drawing::Size(865, 586);
  82.             this->Controls->Add(this->button1);
  83.             this->Controls->Add(this->txtQuery);
  84.             this->Name = L"Form1";
  85.             this->Text = L"Form1";
  86.             this->ResumeLayout(false);
  87.             this->PerformLayout();
  88.  
  89.         }
  90. #pragma endregion
  91.     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
  92.                  String^ SQLQuery = txtQuery->Text;
  93.                  String^ connectionInfo = "datasource=localhost;port=3306;username=root;password=admin;database=programmers";
  94.                  MySqlConnection^ conn = gcnew MySqlConnection(connectionInfo);
  95.                  MySqlCommand^ connCmd = gcnew MySqlCommand(SQLQuery, conn);
  96.                  MySqlDataReader^ dataReader;
  97.  
  98.                  try{
  99.                     conn->Open();
  100.                     dataReader=connCmd->ExecuteReader();
  101.                     MessageBox::Show("Command Performed");
  102.                  }catch(Exception^ex){
  103.                     MessageBox::Show(ex->Message);
  104.                  }
  105.              }
  106.     };
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement