注册 登录
编程论坛 MySQL论坛

用VC2008连接数据库的程序,总是有错,帮忙看一下。

后会无期99 发布于 2012-06-19 14:27, 2134 次点击
程序代码:
头文件是:
#pragma once
#include <string>
#include <windows.h>
#include ".\mysql-connector-c\include\mysql.h"
#include "..\winxx\ConnectDB.h"
using namespace std;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace winxx {   
    public ref class ConnectDB : public System::Windows::Forms::Form
    {
    private:
        MYSQL * mysql;   
    public:
        ConnectDB(void)
        {
        InitializeComponent();
         }   
    protected:
        ~ConnectDB()
        {
            if (components)
            {
                delete components;
            }
         }
   
        System::Windows::Forms::Button^  button1;

        System::ComponentModel::Container ^components;

#pragma region
        void InitializeComponent(void)
        {
           
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->SuspendLayout();
            //
            // button1
            //
            this->button1->Location = System::Drawing::Point(208, 140);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 23);
            this->button1->TabIndex = 0;
            this->button1->Text = L"button1";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &ConnectDB::button1_Click);
            //
            // ConnectDB
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292, 266);
            this->Controls->Add(this->button1);
            this->Name = L"ConnectDB";
            this->Text = L"ConnectDB";
            this->ResumeLayout(false);
        }
   #pragma endregion
   
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
            {
                mysql=mysql_init(NULL);
_mysql=mysql_real_connect(_mysql,"localhost","root","123","mysql",3306,NULL,0);
             }
   
    };
   
}

源文件是:
#include "StdAfx.h"
#include <sstream>
#include "ConnectDB.h"
namespace winxx
{


 Void button1_Click(System::Object^sender,System::EventArgs^  e)
   
   {

           _mysql=mysql_init(NULL);
_mysql=mysql_real_connect(_mysql,"localhost","root","123","mysql",3306,NULL,0);
    }
}
0 回复
1