C++/CLI 表单应用程序 - 无法从数据库 select
C++/CLI Form Application - Can't select from the database
#pragma once
using namespace System;
using namespace MySql::Data::MySqlClient;
ref class Connect {
public:
static String^ query=L"datasource=localhost;port=3306;username=root;password=test123";
static MySqlConnection^ conDB = gcnew MySqlConnection(query);
static MySqlCommand^ cmdDatabase = gcnew MySqlCommand("SELECT * FROM 199246-4444.table;", conDB);
static MySqlDataReader^ myReader;
};
您好,问题是 'gcnew MySqlCommand("SELECT * FROM 199246-4444.table;", conDatabase);' 不工作。我无法从我的数据库中获取 select,我相信这是因为 199246 和 4444 之间有一个破折号导致了错误。我该如何解决?我试图在 Whosebug 上寻找相同或至少类似的问题,但我找不到任何问题,在 Google 上也找不到。我不想更改数据库名称。
我得到的错误是:
"You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '199246-4444.table' at line 1"
当我尝试使用包含文本的数据库时,它完全有效。但是,数据库名称“199246-4444”不起作用。
更新:
我知道我写道我无法连接到我的数据库。我想写的是,我不能 select 从数据库中取而代之。这修复了它:
static MySqlCommand^ cmdDatabase = gcnew MySqlCommand("SELECT * FROM `199246-4444`.`table`;", conDB);
在 dash
之前,您有数据库名称。
在 connection string 中指定数据库,并将其从查询中删除。
static String^ query=L"datasource=localhost;Database=199246-4444;port=3306;username=root;password=test123";
这样试试:
static MySqlCommand^ cmdDatabase = gcnew MySqlCommand("SELECT * FROM `199246-4444`.`table`;", conDB);
即,将数据库名称 199246-4444
放在反引号中 ``.
#pragma once
using namespace System;
using namespace MySql::Data::MySqlClient;
ref class Connect {
public:
static String^ query=L"datasource=localhost;port=3306;username=root;password=test123";
static MySqlConnection^ conDB = gcnew MySqlConnection(query);
static MySqlCommand^ cmdDatabase = gcnew MySqlCommand("SELECT * FROM 199246-4444.table;", conDB);
static MySqlDataReader^ myReader;
};
您好,问题是 'gcnew MySqlCommand("SELECT * FROM 199246-4444.table;", conDatabase);' 不工作。我无法从我的数据库中获取 select,我相信这是因为 199246 和 4444 之间有一个破折号导致了错误。我该如何解决?我试图在 Whosebug 上寻找相同或至少类似的问题,但我找不到任何问题,在 Google 上也找不到。我不想更改数据库名称。
我得到的错误是:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '199246-4444.table' at line 1"
当我尝试使用包含文本的数据库时,它完全有效。但是,数据库名称“199246-4444”不起作用。
更新:
我知道我写道我无法连接到我的数据库。我想写的是,我不能 select 从数据库中取而代之。这修复了它:
static MySqlCommand^ cmdDatabase = gcnew MySqlCommand("SELECT * FROM `199246-4444`.`table`;", conDB);
在 dash
之前,您有数据库名称。
在 connection string 中指定数据库,并将其从查询中删除。
static String^ query=L"datasource=localhost;Database=199246-4444;port=3306;username=root;password=test123";
这样试试:
static MySqlCommand^ cmdDatabase = gcnew MySqlCommand("SELECT * FROM `199246-4444`.`table`;", conDB);
即,将数据库名称 199246-4444
放在反引号中 ``.