C# Reading data from existing SQLite database

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-10 10:26:52

问题


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.

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.

Thanks in advance.


回答1:


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/

It is simple, and it works fine.

You will be able to use VS Designers tools as well as to have strongly typed classes.

The only first thing you will need is to create a connection using the Windows ODBC Data Source Tool.

Or you can use a reg file like :

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.

You can install the x32 or x64 driver or both.

Then you can use the VS Designer generated typed child DataSet and any other classes, and/or the OdbcConnection class and OdbcCommand...

I recommend you this book if you need to learn ADO.NET:

Beginning C# 2005 Databases



来源:https://stackoverflow.com/questions/62641555/c-sharp-reading-data-from-existing-sqlite-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!