在.net 4.0中使用SQLite的内存数据库

时间:2022-06-01 22:09:27
在app.config中修改:
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />

  </startup> 

 

然后: 

        Dim SQLconnect As New SQLite.SQLiteConnection()

        Dim SQLcommand As SQLiteCommand
        SQLconnect.ConnectionString = "Data Source=:memory:;Version=3;New=true"
        SQLconnect.Open()
        SQLcommand = SQLconnect.CreateCommand
        SQLcommand.CommandText = "CREATE TABLE foo(title TEXT, description TEXT)"
        SQLcommand.ExecuteNonQuery()
        SQLcommand.CommandText = "INSERT INTO foo (title, description) VALUES ('This is a title', 'This is a Description')"
        SQLcommand.ExecuteNonQuery()
        SQLcommand.CommandText = "SELECT * FROM foo"
        Dim SQLreader As SQLiteDataReader = SQLcommand.ExecuteReader()
        While SQLreader.Read()
            MessageBox.Show(SQLreader.Item(0).ToString)
        End While
        SQLcommand.Dispose()
        SQLconnect.Close()