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!

3
  • Sql Injection warning xkcd.com/327 Commented May 13, 2016 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 : tutorialspoint.com/mysql/mysql-create-tables.htm Commented May 13, 2016 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 :) Commented May 13, 2016 at 14:57

1 Answer 1

1

Your create table sintaxis is wrong.

You need define field datatype

CREATE TABLE Table1
    (`myDate` datetime)
;
Sign up to request clarification or add additional context in comments.

1 Comment

@EuniceLing, don't forget to mark the question as answered if you've managed to solve your problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.