简体   繁体   English

C#在.sqlite文件(而不是.db)中使用数据

[英]C# Using data in a .sqlite file (not a .db)

So i'm kind of new to SQL and such however I have been using c# for a while. 所以我是SQL的新手,但是我已经使用c#一段时间了。 This is my first question on StackOverflow so if I did something wrong let me know. 这是我关于StackOverflow的第一个问题,所以如果我做错了事,请告诉我。

The file I want to use is not a .db file which is what most of the info I've read is about. 我要使用的文件不是.db文件,这是我已阅读的大多数信息的内容。 It's a .sqlite file and I was wondering how I would be able to use the data in it for a program I'm writing. 这是一个.sqlite文件,我想知道如何在正在编写的程序中使用其中的数据。 I would prefer to not use a third party resource but I will if I have to. 我宁愿不使用第三方资源,但如果需要的话,我会使用。 The file also changes every few days so I don't want to simply convert it externally to .csv or something. 该文件每隔几天也会更改一次,因此我不想简单地将其从外部转换为.csv或其他内容。

Like I said I don't know much about SQL so any help is appreciated. 就像我说的那样,我对SQL不太了解,因此不胜感激。 If someone could show me how to make this data usable I would be very thankful. 如果有人可以告诉我如何使这些数据可用,我将非常感激。

EDIT: Ok so i'm using Visual Studio 2015 to write the code and the file does not contain any commands just stats sort of like an excel file. 编辑:好的,所以我正在使用Visual Studio 2015编写代码,并且该文件不包含任何命令,只是stats有点像excel文件。 It has 14 different tables each having info on different things. 它有14个不同的表,每个表具有有关不同事物的信息。 I'm going to try the method recommended by @inquisitive_mind and I'll let you all know if it worked. 我将尝试@inquisitive_mind推荐的方法,我会告诉大家它是否有效。 Thanks for the help so far! 感谢你目前的帮助! :) :)

Below is the code to read data from SQL Lite databases.You need to download the following dll System.Data.SQLite.dll and reference that in your project.The dll can be found here SQL Lite 下面是从SQL Lite数据库读取数据的代码。您需要下载以下dll System.Data.SQLite.dll并在您的项目中引用它.dll可以在此处找到SQL Lite

For example:I have a table called Scalars with 3 columns in the .sqlite file located in the variable sFilePath.So the code to get the data would look something like this 例如:我在变量sFilePath中的.sqlite文件中有一个名为Scalars的表,其中有3列,因此获取数据的代码看起来像这样

using System.Data.SQLite;

using (SQLiteConnection oSqlLiteConnection = new SQLiteConnection("Data Source=" + sFilePath))
{
     oSqlLiteConnection.Open();
     SQLiteCommand cmd = new SQLiteCommand("Select * from Scalars", oSqlLiteConnection);
     SQLiteDataReader dr = cmd.ExecuteReader();

     while (dr.Read())
         Console.WriteLine(String.Format("{0}\t{1}\t{2}\t{3}", dr.GetValue(0), dr.GetValue(1), dr.GetValue(2)));
}

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

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