简体   繁体   English

如何在 C# 和 WPF 的实体框架中创建数据库和表?

[英]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.

相关问题 如何仅获取特定表以使用 C# 中的 Entity Framework Core 从数据库创建模型 - How to get only specific tables to create models from database with Entity Framework Core in C# 如何使用实体框架在WPF c#中的两个表之间插​​入一对多关系的数据? - How to insert data for one to many relationship between two tables in WPF c# using Entity Framework? C#实体框架在向数据库添加数据时未更新Wpf GUI - C# Entity Framework Not Updating Wpf GUI on Adding Data to Database C#-WPF实体框架-从数据库中删除选定的记录 - C# - WPF Entity Framework - Remove Selected Record from Database 实体框架在运行时创建多个表 C# - Entity Framework create multiple tables at runtime C# 如何使用C#-WPF-Entity-Framework Code First应用程序创建数据库备份? - How do I create database backups using C#-WPF-Entity-Framework Code First application? 如何在数据库中创建表,该表存储来自MS Access数据库中2个不同表的数据c#WPF中 - How to create table in database that stores data from 2 different tables in MS access Database in c# WPF 如何使用Entity Framework 6在运行时创建数据库和表? - How can I create a database and tables at runtime using Entity Framework 6? C# - Entity Framework Core - 自动创建数据库 - C# - Entity Framework Core - auto create database 如何使用C#和Entity Framework在WPF中备份和还原SQL Server - How to backup and restore SQL Server in WPF with C# and Entity Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM