SQLite basic example
I am trying to create a database with SQLite with c# then create a table insert data then close the connection. I have just downloaded System.Data.SQLite.dll lybrary and I am not sure how to use it. There are a lot of examples in the internet but all of them seem to have a database already. Or maybe I am doing something wrong.
开发者_开发百科It will be nice If I can have a short example to just create a database, table and basic query.
EDIT
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?
The error was because I was using .NET Framework 4.0 . I downgraded to 2.0 and it worked. Sorry for the question. It will be nice to use it with .NET Framework 4.0 though.
Edit:
It actually works with .NET Framework 4.0 I had to add this lines of code to my app.config file:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
also if you plan to use ado.net in your solution I experience a lot of problems when deploying. Everything worked great under development. If you use ado.net and you plan on deploying your app then include also:
<!--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.
if you deploy make sure that you copy those files to the working directory
shouldnt it be {"FailIfMissing", "False"}
instead of {"FailIfMissing=False", "False"}
?
Please change the Platform Target for your C# project to Project Settings > Build > Platform Target: Any CPU.
I had a similar error occurred when i tried to run in a x64 machine with SQLite x64 binaries. But worked fine after these settings were changed
精彩评论