简体   繁体   English

C# 从现有 SQLite 数据库中读取数据

[英]C# Reading data from existing SQLite database

I am working on a small project.我正在做一个小项目。 Building a text based football simulator.构建基于文本的足球模拟器。 I have set up an database with SQLite with the basic information such as Name, Surname, Attack, Defense what I need some help with is reading the database into my C# script to be able to use these values in my existing database.我已经使用 SQLite 建立了一个数据库,其中包含姓名、姓氏、攻击、防御等基本信息,我需要一些帮助的是将数据库读入我的 C# 脚本,以便能够在我现有的数据库中使用这些值。

In short I want to call on a player with C# and read the information in the database into a variable for me to do further calculations with.简而言之,我想用 C# 调用一个播放器,并将数据库中的信息读入一个变量,以便我进行进一步的计算。

Thanks in advance.提前致谢。

On Windows, as well as Linux, you can use ADO.NET and a DataSet with a SQLite ODBC Driver. On Windows, as well as Linux, you can use ADO.NET and a DataSet with a SQLite ODBC Driver.

http://www.ch-werner.de/sqliteodbc/ http://www.ch-werner.de/sqliteodbc/

It is simple, and it works fine.这很简单,而且效果很好。

You will be able to use VS Designers tools as well as to have strongly typed classes.您将能够使用 VS Designers 工具以及拥有强类型的类。

The only first thing you will need is to create a connection using the Windows ODBC Data Source Tool.您唯一需要做的第一件事就是使用 Windows ODBC 数据源工具创建连接。

Or you can use a reg file like:或者您可以使用 reg 文件,例如:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\DatabaseName]
"Driver"="C:\\Windows\\system32\\sqlite3odbc.dll"
"Description"=""
"Database"="%USERPROFILE%\\AppData\\Roaming\\Company\\Application\\DatabaseName.sqlite"
"Timeout"=""
"StepAPI"="0"
"SyncPragma"=""
"NoTXN"="0"
"ShortNames"="0"
"LongNames"="0"
"NoCreat"="0"
"NoWCHAR"="0"
"FKSupport"="1"
"OEMCP"="0"
"LoadExt"=""
"BigInt"="0"
"JDConv"="0"
"PWD"=""

[HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC Data Sources]
"DatabaseName"="SQLite3 ODBC Driver"

Replace DatabaseName , Company and Application by what you want, or use any path and extension you need.DatabaseNameCompanyApplication替换为您想要的,或使用您需要的任何路径和扩展名。

You can install the x32 or x64 driver or both.您可以安装 x32 或 x64 驱动程序或同时安装两者。

Then you can use the VS Designer generated typed child DataSet and any other classes, and/or the OdbcConnection class and OdbcCommand...然后,您可以使用 VS Designer 生成的类型化子数据集和任何其他类,和/或 OdbcConnection class 和 OdbcCommand ...

I recommend you this book if you need to learn ADO.NET:如果你需要学习 ADO.NET,我推荐你这本书:

Beginning C# 2005 Databases 开始 C# 2005 数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM