C# 的便携式数据库

发布于 2024-12-04 17:35:12 字数 169 浏览 0 评论 0原文

我知道这似乎是一个已经被问过的问题,但我已经尝试了那里的解决方案。

我正在使用 C# 构建一个程序,我需要以每个客户端都有自己的数据库新鲜(动态路径)的方式保存数据。我该怎么做才能让用户不需要安装额外的东西,而只需要安装 .NET 框架?

我听说过 SQLite,但我并没有真正让它发挥作用。

I know that this may seem as a question that was already asked, but I tried the solutions out there already.

I am building a program with C# and I need to save data in a way that every client has his own fresh (dynamic path) to his db. What can I do so users won't need to install extra things, but just .NET framework?

I heard about SQLite, but I didn't really get it working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

尘曦 2024-12-11 17:35:12

此处下载 SQLite .NET 数据提供程序,然后从应用程序中引用 System.Data.SQLite.dll。下面的例子应该可以立即运行。

using (var connection = new SQLiteConnection("Data Source=yourfile.db;Version=3;"))
using (var command = connection.CreateCommand())
{
  connection.Open();
  command.CommandText = "select name from from sqlite_master";
  using (var reader = command.ExecuteReader())
  {
    while (reader.Read())
    {
      Console.WriteLine(Convert.String(reader["name"]));
    }
  }
}

当然,它所做的只是列出指定文件中的表。如果该文件不存在,那么它将自动创建,并且自然不会有任何表在其中。但是,至少它应该可以工作。

Download the SQLite .NET data provider here and then reference System.Data.SQLite.dll from within your application. The following example should work right off the bat.

using (var connection = new SQLiteConnection("Data Source=yourfile.db;Version=3;"))
using (var command = connection.CreateCommand())
{
  connection.Open();
  command.CommandText = "select name from from sqlite_master";
  using (var reader = command.ExecuteReader())
  {
    while (reader.Read())
    {
      Console.WriteLine(Convert.String(reader["name"]));
    }
  }
}

Of course all it does is list the tables in the specified file. If the file does not exist then it will be created automatically and naturally there will not be any tables in it. But, at the very least it should work.

晨曦÷微暖 2024-12-11 17:35:12

官方 SQLite 快速入门:

http://www.sqlite.org/quickstart.html

代码示例对于 System.Data.Sqlite,在原始支持论坛上:

http://sqlite.phxsoftware.com/forums/t/76.aspx

您可以在这个相关 SO 问题的答案中找到 SQLite 的一些替代方案:

SQLite 的替代品?

The official SQLite QuickStart:

http://www.sqlite.org/quickstart.html

Code samples for System.Data.Sqlite, on the original support forums:

http://sqlite.phxsoftware.com/forums/t/76.aspx

You can find a few alternatives to SQLite in the answers to this related SO question:

Alternatives to SQLite?

风吹过旳痕迹 2024-12-11 17:35:12

如果我没记错的话,c#.net 可以与 sql 数据库交互,而无需单独的服务器软件。您只需导入 system.data.sqlclient 即可。

SQL 可能适合您,但没有简单的方法来开始使用它的原因是数据库架构不是一个简单的主题。如果您选择走这条路,有很多很棒的书籍可以帮助您入门。它专门讨论 MSSQL 的语法,但 Itzik Ben-Gan 的“T-SQL 基础知识”是一本很有帮助的书。当然,不同 SQL 迭代之间的语法差异是非常常见的,一旦您了解了您碰巧正在处理的 SQL 的特性,就不再是一个巨大的负担。

If I'm not mistaken, c#.net can interface with a sql database without separate server software. You would just import system.data.sqlclient.

SQL could work for you, but the reason that there is no simple way to get started with it is that database architecture is not a simple subject. There are plenty of great books out there to get you started if you choose to go that route. It deals specifically with the syntax of MSSQL, but "T-SQL Fundamentals" by Itzik Ben-Gan is a helpful one. Of course, syntax variations between different iterations of sql are extremely common, and not a huge burden once you know the idiosyncrasies of the one you happen to be dealing with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文