[英]How create database and tables in Entity Framework in C# and WPF?
I build an app that works with MySQL server and I make it do the migration and it works fine.我构建了一个与 MySQL 服务器一起使用的应用程序,我让它进行迁移,它工作正常。
But I also want to create the database first in Mysql command line, then do the migration.但我也想先在 Mysql 命令行中创建数据库,然后进行迁移。
Like execute this query first, then do the migrations:就像先执行这个查询,然后做迁移:
CREATE database `ahmed` DEFAULT CHARACTER SET ascii COLLATE ascii_general_ci ;
You can try something like this:你可以尝试这样的事情:
try
{
string conn = @"server=localhost;userid= ;password= ";
using (MySqlConnection connection = new MySqlConnection(conn))
{
connection.Open();
string command = "CREATE database `ahmed` DEFAULT CHARACTER SET ascii COLLATE ascii_general_ci;";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.ExecuteNonQuery();
MessageBox.Show("Created databaase");
}
}
catch (MySqlException ex)
{
MessageBox.Show("Error: " + ex);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.