Check here, it will walk you through what you need to do...if you have any specific issues with specific parts of the linked process, let us know.
Creating and utilizing a local database in Visual Studio 2010
-
16-01-2022 - |
質問
I can't seem to find any straight-forward guides on how to create a windows forms application with C# .NET in Visual Studio 2010 that uses a local database. When I create the local database, a .sdf file, I can't figure out how to have my form access it. All the discussions I have been able to find on it seem to assume I know more than I do on the subject. Can anyone direct me towards a straight-forward beginner's guide on the subject, or outline the steps I need to take?
解決
他のヒント
I found this library very helpful
https://github.com/martincostello/sqllocaldb
Once added via nuget its very easy to use
ISqlLocalDbProvider provider = new SqlLocalDbProvider();
ISqlLocalDbInstance instance = provider.GetOrCreateInstance("MyInstance");
instance.Start();
using (SqlConnection connection = instance.CreateConnection())
{
connection.Open();
// Use the connection...
}
instance.Stop();
所属していません StackOverflow