Подключение VB к MySQL

Я хотел бы попросить некоторую помощь о том, как подключить VB6 к MYSQL? Пожалуйста, предоставьте также ссылки.

Большое спасибо

2 ответа

Google указывает, что вы можете использовать ADO и драйверы ODBC MySQL.

Dim strConnection$, conn As Connection 

'Fill in the placeholders with your server details'
strConnection = "Driver={MySQL ODBC 3.51 Driver};Server=myServerAddress;" & _ 
   "Database=myDataBase;User=myUsername;Password=myPassword;Option=3"

Set conn = New Connection  
conn.Open strConnection

Строка подключения ODBC для MySQL отсюда.

Предупреждение: воздушный код. Я никогда не делал это сам.

Ссылка: http://paulbradley.tv/37/

Этот фрагмент кода демонстрирует, как подключиться к базе данных MySQL из приложения для Windows, написанного на Visual Basic 6. С помощью драйвера ODBC MySQL и удаленного объекта данных Microsoft довольно легко подключаться и извлекать записи с сервера базы данных MySQL.

■ Загрузите и установите драйвер MySQL ODBC.

■ Настройте комбинацию имени пользователя и пароля MySQL, которая позволит устанавливать соединения с любого хоста. Смотрите команду предоставления MySQLs.

■ Запустите новый проект Visual Basic и добавьте объект данных Microsoft Remote. В меню выберите "Проект" | Ссылки, а затем выберите Microsoft Remote Data Object из списка.

Образец кода

Private Sub cmdConnectMySQL_Click()

Dim cnMySql As New rdoConnection
Dim rdoQry  As New rdoQuery
Dim rdoRS   As rdoResultset

' set up a remote data connection
' using the MySQL ODBC driver.
' change the connect string with your username,
' password, server name and the database you
' wish to connect to.

cnMySql.CursorDriver = rdUseOdbc
cnMySql.Connect = "uid=YourUserName;pwd=YourPassword;
    server=YourServerName;" & _
    "driver={MySQL ODBC 3.51 Driver};
    database=YourDataBase;dsn=;"
cnMySql.EstablishConnection

' set up a remote data object query
' specifying the SQL statement to run.

With rdoQry
    .Name = "selectUsers"
    .SQL = "select * from user"
    .RowsetSize = 1
    Set .ActiveConnection = cnMySql
    Set rdoRS = .OpenResultset(
            rdOpenKeyset, rdConcurRowVer)
End With

' loop through the record set
' processing the records and fields.

Do Until rdoRS.EOF
    With rdoRS

    ' your code to process the fields
    ' to access a field called username you would
    ' reference it like !username

        rdoRS.MoveNext
    End With
Loop

' close record set
' close connection to the database

rdoRS.Close
cnMySql.Close

End Sub
#include <iostream>
#include <sstream>

#include <cpr/cpr.h>
#include <elmo.hpp>

void appInit(char *args) {

}

int main(int argc, char *argv) {

if (argc > 1) {
    appInit(argv);
} else {
    std::cout << "Usage: a.out [search keyword]" << std::endl;
}

int limit = 3;

cpr::Parameters parameters{{"query", input},
                    {"limit", "3"},
                    {"indent", "true"},
                    {"key", "AIzaSyA5Xr82w7LrJgaLPb99P4kVZzFlxYuPhng"}};

auto response = cpr::Get(cpr::Url{
    "https://kgsearch.googleapis.com/v1/entities:search"}, parameters);

auto elmo = nlohmann::elmo::parse(response.text);
elmo.flatten();

for (int i=0; i<limit; i++) {
    std::ostringstream oss;
    std::cout << elmo["/itemListElement/0/result/name"_elmo_pointer];
    //std::cout << elmo["/itemListElement/i/result/@type/0"_elmo_pointer] << std::endl;
    //std::cout << elmo["/itemListElement/i/result/@type/1"_elmo_pointer] << std::endl;
    std::cout << elmo["/itemListElement/0/result/description"_elmo_pointer] << std::endl;
    std::cout << elmo["/itemListElement/0/result/detailedDescription/articleBody"_elmo_pointer] << std::endl;
    std::cout << elmo["/itemListElement/0/result/image/url"_elmo_pointer] << std::endl;
}

//std::cout << json.dump(4) << std::endl;
}
Другие вопросы по тегам