[英]How to add SQLite (SQLite.NET) to my C# project
我按照文档中的说明操作:
场景1:版本无关(不使用全局程序集缓存)
此方法允许您将任何新版本的System.Data.SQLite.DLL删除到应用程序的文件夹中,并在不进行任何代码修改或重新编译的情况下使用它。 将以下代码添加到app.config文件中:
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>
我的app.config文件现在看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="DataFeed.DataFeedSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<DataFeed.DataFeedSettings>
<setting name="eodData" serializeAs="String">
<value>False</value>
</setting>
</DataFeed.DataFeedSettings>
</userSettings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider"
invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>
我的项目名为“DataFeed”:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite; //<-- Causes compiler error
namespace DataFeed
{
class Program
{
static void Main(string[] args)
{
}
}
}
我得到的错误是:
。\\ dev \\ DataFeed \\ Program.cs(5,19):错误CS0234:命名空间“System.Data”中不存在类型或命名空间名称“SQLite”(您是否缺少程序集引用?)
我不想使用GAC,所以我只是将System.Data.SQLite.dll
放入我的.\\dev\\DataFeed\\
文件夹中。 我认为我需要做的就是将DLL添加到文档中提到的项目文件夹中,但我无法使用该库。 关于如何实现这项工作的任何提示?
您将DLL删除到.\\Dev\\DataFeed
文件夹中 - 并且您是否已将该DLL的引用添加到您的项目中? 你得到的错误似乎表明你没有设置到该DLL的引用 - 这不会单独发生,如果你想使用它的东西,你需要手动添加对外部DLL的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.