.NET Window Forms local database(.NET 窗口窗体本地数据库)
问题描述
我刚开始编写 Windows 窗体应用程序,我想将数据存储在数据库中,而不是实际的数据库服务器中.类似于 SQLite(本地,独立于服务器).
I just started writing a Windows Forms Application and I'd like to store data in a Database but not in an actual DB Server.. something like SQLite (local, server independent).
.NET 有这样的开箱即用的东西吗?我查看了 DataSets,但我很难填充它.
Does .NET have anything like this out of the box? I looked into DataSets but I'm have a hard time populating it.
不胜感激,谢谢!
推荐答案
考虑一下 Sql Server Compact 版本,你可以找到如何将它添加到你的项目中的说明 这里.下面的示例代码从包含数据库文件 MyDb.sdf 中的列 Id 的表 MyTable 中检索数据,您还需要添加 System.Data.SqlServerCe 程序集引用和命名空间 System.Data.SqlServerCe
Consider Sql Server Compact edition, you can find instruction how to add it to your project here. Below sample code to retrieve data from the table MyTable containing column Id in database file MyDb.sdf, you also need to add System.Data.SqlServerCe assembly reference and namespace System.Data.SqlServerCe
using (SqlCeConnection ceConn = new SqlCeConnection(@"Data Source=|DataDirectory|MyDb.sdf"))
using (SqlCeCommand ceCmd = new SqlCeCommand("select Id from MyTable", ceConn))
{
ceConn.Open();
SqlCeDataReader dataR = ceCmd.ExecuteReader();
while (dataR.Read())
{
Console.WriteLine(dataR["Id"].ToString());
}
}
这篇关于.NET 窗口窗体本地数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.NET 窗口窗体本地数据库


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01