1

This error occurs whenever i'm trying to run my program.

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

The code is as follows:

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();
    }
}

I still can't manage to solve this error. Thanks for the help!

Garamaru
  • 106
  • 1
  • 1
  • 11
Annie
  • 29
  • 2
  • Sql Injection warning https://xkcd.com/327/ – Juan Carlos Oropeza May 13 '16 at 14:49
  • For starters, **DO NOT** use this inside your click event (as @JuanCarlosOropeza) has stated - terrible design. Secondly, your command string `"...(" + "name" + ")"` is the same as `"(name)"` (WHYYYY!?), which is causing your error. Your parens (`()`) should contain a list of column definitions... Check out how MySQL syntax should be : http://www.tutorialspoint.com/mysql/mysql-create-tables.htm – Geoff James May 13 '16 at 14:51
  • Another good pointer is in your error (and I quote...): "_check the manual that corresponds to your MySQL server version for the right syntax to use_"... Go RTFM :) ... @JuanCarlosOropeza has answered correctly below :) – Geoff James May 13 '16 at 14:57

1 Answers1

1

Your create table sintaxis is wrong.

You need define field datatype

CREATE TABLE Table1
    (`myDate` datetime)
;
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118