I installed a MySql.Data NuGet Package to my project
and tried to create table using ExecuteNonQuery.
using (MySqlConnection con = new MySqlConnection(connectionString))
{
con.Open();
MySqlCommand sqlCommand = new MySqlCommand();
sqlCommand.Connection = con;
string cmd = @"CREATE TABLE [TABLENAME] (
TIMESTAMP VARCHAR(30) NOT NULL,
TAGNAME NVARCHAR(250) NOT NULL,
MESSAGE NVARCHAR(1000) NOT NULL,
LIMITTYPE NVARCHAR(100) NOT NULL,
CLASSNAME NVARCHAR(100) NOT NULL,
STATE NVARCHAR(20) NOT NULL,
PRIMARY KEY (TIMESTAMP, TAGNAME),
KEY IDX_[TABLENAME] (TIMESTAMP, TAGNAME)
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
sqlCommand.CommandText = cmd.Replace("[TABLENAME]", tableName);
sqlCommand.ExecuteNonQuery();
}
You can see the code above.
However, when I execute that command, it throws NullReferenceException from sqlCommand.ExecuteNonQuery();
.
And, I go to my MySql workbench and can find the table is created and have a row with all null values which is not permitted.
Like this,
enter image description here
Why is this happening, and how can I stop it?
I executed the query from workbench itself and there is no row inserted.
I want to create a table only without insert a row.