简体   繁体   English

如何在 Visual Studio 2017 中使用 SQLite?

[英]How to use SQLite in Visual Studio 2017?

I'm using Visual Studio 2017, in UWP project.我在 UWP 项目中使用 Visual Studio 2017。 I installed SQLite Compact Toolbox from NuGet package like this:我从 NuGet 包安装了 SQLite Compact Toolbox,如下所示:

  • Microsoft.Data.sqlite / sqlite-net / sqlite-net-pcl / System.Data.SQLite Microsoft.Data.sqlite / sqlite-net / sqlite-net-pcl / System.Data.SQLite

After that, I still can't add using Microsoft.Data.Sqlite in MainPage.xaml.cs to read values in my table and make a query.之后,我仍然无法在MainPage.xaml.cs 中添加using Microsoft.Data.Sqlite来读取表中的值并进行查询。

How can I be able to add using Microsoft.Data.Sqlite ?我怎样才能using Microsoft.Data.Sqlite添加?

Add SQLite/SQL Server Compact Toolbox from In Visual Studio 2017 Community.从 Visual Studio 2017 社区中添加 SQLite/SQL Server Compact Toolbox。 Goto Tools - Extensions and Updates - click Online.转到工具 - 扩展和更新 - 单击在线。 Search for Sqlite.搜索 Sqlite。 You should see Sqlite compact toolbox.您应该会看到 Sqlite compact 工具箱。 Click download .点击下载。 Restart visual studio.重新启动视觉工作室。

how to use sqlite in visual studio 2017如何在 Visual Studio 2017 中使用 sqlite

I'd recommend you to follow this latest tutorial to use a SQLite database in a UWP app.我建议您按照此最新教程在 UWP 应用中使用 SQLite 数据库。

And i can't add using Microsoft.Data.Sqlite而且我无法添加使用 Microsoft.Data.Sqlite

If you installed the Microsoft.Data.Sqlite Nuget package, but cannot reference the Microsoft.Data.Sqlite namespace, you may need to check the versions of UWP app,package and Microsoft.NETCore.UniversalWindowsPlatform .如果您安装了Microsoft.Data.Sqlite Nuget 包,但无法引用Microsoft.Data.Sqlite命名空间,则可能需要检查 UWP 应用程序、包和Microsoft.NETCore.UniversalWindowsPlatform的版本。 As the article mentioned,if the minimum version of your project does not target the Fall Creators Update, you need to upgrade Microsoft.NETCore.UniversalWindowsPlatform package to 5.2.2 (or higher) and install version 1.1.1 (or lower) of Microsoft.Data.Sqlite package.如文章所述,如果您的项目最低版本不针对 Fall Creators Update,则需要将Microsoft.NETCore.UniversalWindowsPlatform包升级到 5.2.2(或更高)并安装Microsoft.Data.Sqlite 1.1.1(或更低)版本Microsoft.Data.Sqlite包。 Details please check The minimum version of your project does not target the Fall Creators Update section.详细信息请查看您的项目的最低版本不针对秋季创作者更新部分。

There're many Nuget packages for SQLite, some of them are older with long time no updating. SQLite 有很多 Nuget 包,其中一些比较旧,很长时间没有更新。 Install many packages at a same time may lead conflicts.Try un-install them all and just following above tutorial.同时安装多个包可能会导致冲突。尝试将它们全部卸载并按照上述教程进行操作。

There is a sample which use the old SQLite.Net-PCL package you could also reference if you do want to use other packages.一个使用旧SQLite.Net-PCL的示例,如果您确实想使用其他包,也可以参考。

It is 2021 and I'm on VS2017 still.现在是 2021 年,我还在 VS2017 上。 The only thing I could get to work in the tutorial recommended by Wu was using the part of the tutorial about using the version of sqlite included with Windows.在 Wu 推荐的教程中,我唯一能做的就是使用教程中关于使用 Windows 附带的 sqlite 版本的部分。 Everything else would no longer install with uwp 10.其他所有东西将不再安装 uwp 10。

As of 1/25/2021:截至 2021 年 1 月 25 日:

Target Windows 10, version 10.0目标 Windows 10,版本 10.0

Target Windows 10 Fall Creators Update 10.0目标 Windows 10 Fall Creators Update 10.0

Use nuget and install these two packages:使用 nuget 并安装这两个包:

Microsoft.Data.SQLite.core Microsoft.Data.SQLite.core

SQLitePCLRaw.bundle_winsqlite3 SQLitePCLRaw.bundle_winsqlite3

I will say it worked to the point I loaded a DataTable with data and debug showed it had two rows in it.我会说它工作到我加载了一个带有数据的 DataTable 并且调试显示它有两行。

I spent all afternoon trying to get sqlite to work.我整个下午都在试图让 sqlite 工作。 It's amazing anyone ever actually gets anything done.任何人都能真正完成任何事情,真是太神奇了。 No wonder companies have to have rooms full of coders!难怪公司必须有充满编码员的房间!

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

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