.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 窗口窗体本地数据库
基础教程推荐
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 如果条件可以为空 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 将数据集转换为列表 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
