Skip to content Skip to sidebar Skip to footer

Insert Data Into Sqlite In-memory Database

So I have a in-memory database and I'm trying to insert data into the table and it's not working. Am I doing something wrong? var connection = new SQLiteConnection('DataSource=:mem

Solution 1:

I just noticed from your code that this line:

command.ExecuteNonQuery();

is called only once. What happens when you do:

varconnection=newSQLiteConnection("DataSource=:memory:;Version=3;New=True;");

connection.Open();

stringsql="CREATE TABLE  recently_viewed(movieid INTEGER,picture TEXT)";

SQLiteCommandcommand=newSQLiteCommand(sql, connection);
command.ExecuteNonQuery();

using ( command = connection.CreateCommand())
{
    command.CommandText = "INSERT into recently_viewed(movieid ,picture) values(@movieid,@picture)";
    command.Prepare();
    command.Parameters.AddWithValue("@movieid", id);
    command.Parameters.AddWithValue("@picture", picture);
    command.ExecuteNonQuery();
}


stringcount_table=" SELECT count(*) FROM recently_viewed";

SQLiteCommandcom3=newSQLiteCommand(count_table, connection);
com3.ExecuteNonQuery();

intctable= Convert.ToInt32(com3.ExecuteScalar().ToString());

Response.Write(ctable);

connection.Close();

Post a Comment for "Insert Data Into Sqlite In-memory Database"