gpt4 book ai didi

mysql - C++/CLI 表单应用程序 - 无法从数据库中选择

转载 作者:行者123 更新时间:2023-11-29 02:22:02 25 4
gpt4 key购买 nike

#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);'不工作。我无法从我的数据库中选择,我相信这是因为 199246 和 4444 之间有一个破折号导致了错误。我该如何解决?我试图在 Stackoverflow 上寻找相同或至少类似的问题,但我找不到任何问题,也没有在 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”不起作用。

更新:

我知道我写道我无法连接到我的数据库。我想写的是我无法从数据库中选择。这修复了它:

static MySqlCommand^ cmdDatabase = gcnew MySqlCommand("SELECT * FROM `199246-4444`.`table`;", conDB);

最佳答案

像这样尝试:

static MySqlCommand^ cmdDatabase = gcnew MySqlCommand("SELECT * FROM `199246-4444`.`table`;", conDB);

即,将数据库名称 199246-4444 放在反引号 `` 中。

关于mysql - C++/CLI 表单应用程序 - 无法从数据库中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30130813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com