This must be very simple but I can't figure it out, or maybe it is not possible.
I have the next function:
private static bool createDB(SqlConnection dbConn, string dbName)
{
string sqlString = "CREATE DATABASE @dbname";
using (dbConn)
{
using (SqlCommand cmd = new SqlCommand(sqlString, dbConn))
{
cmd.Parameters.AddWithValue("@dbname", dbName);
cmd.CommandType = CommandType.Text;
dbConn.Open();
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Se creo la DB");
return true;
}
catch (Exception ex)
{
MessageBox.Show("No se creo la DB");
return false;
}
finally
{
//dbConn.Close();
}
}
}
}
But apparently the @dbname is not getting the value, dbName does gets the name I want when I call it, but the exception says incorrect syntax near '@dbname'.
I'm new to C#, please be nice :) I got this from many other posts with prepared statements, but I couldn't find any with a CREATE DATABASE, but I'm assuming this should be very similar.