代码之家  ›  专栏  ›  技术社区  ›  Kiril

如何将sqlite(sqlite.net)添加到我的c项目

  •  3
  • Kiril  · 技术社区  · 14 年前

    我遵循了文档中的说明:

    场景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:类型或命名空间 名称“sqlite”不存在于 命名空间“system.data”(您是 缺少程序集引用?)

    我不想用GAC所以我就把 System.Data.SQLite.dll 进入我的 .\dev\DataFeed\ 文件夹。我想我所需要做的就是将dll添加到文档中提到的项目文件夹中,但是我不能使用这个库。有什么关于如何让这个工作的提示吗?

    1 回复  |  直到 14 年前
        1
  •  3
  •   marc_s    14 年前

    你把dll放到了 .\Dev\DataFeed 文件夹-您是否向项目中添加了对该dll的引用??您收到的错误似乎表明您没有设置对该dll的引用-这不会单独发生,如果您要使用外部dll中的内容,则需要手动添加对外部dll的引用。