Create mysql database using mysql command [message #168578] |
Mon, 27 May 2013 10:54 |
Jack Hard
Messages: 7 Registered: December 2012
Karma: 0
|
Junior Member |
|
|
I am having a problem when trying to create a database using mysql command. The code i am using is;
using (MySqlConnection con = connect_db())
{
con.Open();
MySqlCommand cmd = new MySqlCommand("CREATE DATABASE @name;", con);
cmd.Parameters.AddWithValue("@name", "fancydb");
try
{
cmd.ExecuteNonQuery();
}
catch (Exception exc)
{
return;
}
cmd.Dispose();
con.Close();
con.Dispose();
}
When i try to run this code i always get an error saying that i have an error in mysql syntax near "fancydb"...but when I put the name in the command like: "CREATE DATABASE facnydb;" it works. Can anyone explain to me why is the error only happening when i try and use parameters?
|
|
|
Re: Create mysql database using mysql command [message #186575 is a reply to message #168578] |
Fri, 03 October 2014 17:27 |
|
ash
Messages: 2 Registered: October 2014 Location: nashik
Karma: 0
|
Junior Member |
|
|
to create a database in mysql we used a command
create database database_name;
then we used that database using,
use database_name;
then create a table
create table table_name;
ASHISH DUSANE
|
|
|
|
|