我必须在客户端系统上安装数据库吗?

do i have to install database on client's system?

我正在 Visual Studio 2019 年为汽车交易创建一个 C# Windows Forms 应用程序。

我的问题是:

  1. 我是否应该使用本地数据库,因为只有一台 PC 上的单个客户端才能使用该应用程序?
  2. 我需要在客户的 PC 上安装数据库吗?

如果有其他方法,我该怎么做?

Sqlite 将是一个很好的解决方案。

https://www.sqlite.org/index.html

"SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day."

正如 NeutralHandle 提到的,您可以将数据保存到 SQLite 中。

在Winforms中使用,按步骤操作即可。

1.Install System.Data.SQLite 来自 Nuget

2.Configure App.config

中的连接字符串
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
  <connectionStrings>
     <add name="SQLiteDbContext" connectionString="Data Source=MyDatabase.sqlite" providerName="System.Data.SQLite.EF6" />
  </connectionStrings>
</configuration>

3.Then参考代码demo

SQLiteConnection.CreateFile("MyDatabase.sqlite");

SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite");
m_dbConnection.Open();

string sql = "create table highscores (name varchar(20), score int)";

SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();

sql = "insert into highscores (name, score) values ('Me', 9001)";

command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();// read
SQLiteCommand sqlCom = new SQLiteCommand("Select * From highscores", m_dbConnection);

SQLiteDataReader sqlDataReader = sqlCom.ExecuteReader();

int i = 1;
while (sqlDataReader.Read())
{
    listBox1.Items.Add(i);
    listBox1.Items.Add(sqlDataReader.GetValue(0));
    listBox1.Items.Add(sqlDataReader.GetValue(1));
    i++;
}

m_dbConnection.Close();