gpt4 book ai didi

c# - 使用 C# 在 MySQL 数据库中创建表时出错

转载 作者:搜寻专家 更新时间:2023-10-30 23:39:13 24 4
gpt4 key购买 nike

每当我尝试运行我的程序时都会出现此错误。

Additional information: 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 ')' at line 1

代码如下:

private void create_Click(object sender, EventArgs e)
{
string MyConnectionString = "Server=x.x.x.x;Database=groupdes_New;Uid=root;Pwd=password;";

//create connection
MySqlConnection connection = new MySqlConnection(MyConnectionString);
//connect to database
connection.Open();

MySqlCommand cmd;
cmd = connection.CreateCommand();//create command
cmd.CommandText = "CREATE Table Newtable (" + "name" + ")";
cmd.ExecuteNonQuery();

if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}

我仍然无法解决这个错误。感谢您的帮助!

最佳答案

您的 create table 语法错误。

您需要定义字段数据类型

CREATE TABLE Table1
(`myDate` datetime)
;

关于c# - 使用 C# 在 MySQL 数据库中创建表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37213039/

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