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

时间:2016-05-13 14:45:07

标签: c# mysql database database-table

每当我试图运行我的程序时都会发生此错误。

  

其他信息:您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在附近使用')'在第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();
    }
}

我仍然无法解决此错误。谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

你的创建表sintaxis是错误的。

您需要定义字段数据类型

CREATE TABLE Table1
    (`myDate` datetime)
;