简体   繁体   中英

How to make a SQL Server 2017 local database from C# code in Visual Studio 2017?

I am trying to write a console game in C#, however, I am running into trouble trying to generate my database for information on the characters, and stage.

My questions are: how do I

  1. Create a database file from C# code?
  2. Connect to that database after it is been created?
  3. And how to add tables to that database from C# code?

I was thinking that I could use fileinfo and filestream classes to make the .mdf file, but I would rather be safe by asking you guys.

.net for c# has a library for this, the using statement has to be activated manually though. If you click project in visual studio and click add reference and go to the extras. Mysql.data should have everything you need. And you can connect to the data base by just making a string out of the command. But connect to the database first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM