C# 从现有的 SQLite 数据库读取数据 [英] C# Reading data from existing SQLite database

查看:23
本文介绍了C# 从现有的 SQLite 数据库读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个小项目.构建基于文本的足球模拟器.我已经使用 SQLite 建立了一个包含姓名、姓氏、攻击、防御等基本信息的数据库,我需要帮助的是将数据库读取到我的 C# 脚本中,以便能够在我现有的数据库中使用这些值.

简而言之,我想用 C# 调用一个播放器并将数据库中的信息读入一个变量中,以便我做进一步的计算.

提前致谢.

解决方案

在 Windows 和 Linux 上,您可以使用 ADO.NET 和带有 SQLite ODBC 驱动程序的数据集.

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

它很简单,而且效果很好.

您将能够使用 VS Designers 工具以及拥有强类型的类.

您唯一需要做的第一件事是使用 Windows ODBC 数据源工具创建连接.

或者你可以使用像这样的 reg 文件:

Windows 注册表编辑器 5.00 版[HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\DatabaseName]驱动程序"=C:\\Windows\\system32\\sqlite3odbc.dll";描述"="数据库"=%USERPROFILE%\\AppData\\Roaming\\Company\\Application\\DatabaseName.sqlite"超时"="StepAPI"=0"SyncPragma"="NoTXN"=0"ShortNames"=0"长名称"=0"NoCreat"=0"NoWCHAR"=0"FKSupport"=1"OEMCP"=0"LoadExt"="BigInt"=0"JDConv"=0"PWD"="[HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC 数据源]DatabaseName"=SQLite3 ODBC 驱动程序"

DatabaseNameCompanyApplication 替换为您想要的,或使用您需要的任何路径和扩展名.

您可以安装 x32 或 x64 驱动程序,或者两者都安装.

然后您可以使用 VS 设计器生成的类型化子 DataSet 和任何其他类,和/或 OdbcConnection 类和 OdbcCommand...

如果您需要学习 ADO.NET,我向您推荐这本书:

开始 C# 2005 数据库

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.

解决方案

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

这篇关于C# 从现有的 SQLite 数据库读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆