English 中文(简体)
SQLite基本示例
原标题:SQLite basic example
  • 时间:2011-05-28 05:59:16
  •  标签:
  • c#
  • sqlite

我正试图用c#创建一个带有SQLite的数据库,然后创建一个表插入数据,然后关闭连接。我刚刚下载了System.Data.SQLite.dll lybrary,我不知道如何使用它。互联网上有很多例子,但似乎所有的例子都已经有了数据库。或者我做错了什么。

如果我能有一个简短的例子来创建一个数据库、表和基本查询,那就太好了。

编辑

I have tried the examples provided by the comments but I don t understand why I do get errors. Maybe I downloaded the wrong library? enter image description here

最佳回答

错误是因为我使用的是.NET Framework 4.0。我降级到2.0,它起作用了。很抱歉问你这个问题。不过,将它与.NET Framework 4.0一起使用会很好。


编辑:

它实际上可以与.NET Framework 4.0配合使用。我不得不将以下几行代码添加到我的app.config文件中:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0.30319" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>

此外,如果你计划在你的解决方案中使用ado.net,我在部署时会遇到很多问题。在开发过程中一切都很顺利。如果你使用ado.net并计划部署你的应用程序,那么还包括:

<!--Sqlite configuration so that it works with ado.net-->
<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>

if you include that last part in your app.config file then you will have to make sure that:

those dll s have to be in your output directory.

如果进行部署,请确保将这些文件复制到工作目录

问题回答

它不应该是{“FailIfMissing”,“False”}而不是}{“FailIfMissing=False”,“False”}[/code>吗?

请将C#项目的平台目标更改为项目设置>;生成>;平台目标:任何CPU。

当我尝试在带有SQLite x64二进制文件的x64计算机上运行时,也发生了类似的错误。但更改这些设置后运行良好





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...