![](/img/trans.png)
[英]Fluent NHibernate: SQLite in-memory database and GUID generated on insert
[英]Insert data into sqlite in-memory database
因此,我有一個內存數據庫,並且正在嘗試將數據插入表中,並且該表無法正常工作。 難道我做錯了什么?
var connection = new SQLiteConnection("DataSource=:memory:;Version=3;New=True;");
connection.Open();
string sql = "CREATE TABLE recently_viewed(movieid INTEGER,picture TEXT)";
SQLiteCommand command = new SQLiteCommand(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);
}
string count_table = " SELECT count(*) FROM recently_viewed";
SQLiteCommand com3 = new SQLiteCommand(count_table, connection);
int ctable = Convert.ToInt32(com3.ExecuteScalar().ToString());
Response.Write(ctable);
connection.Close();
我剛剛從您的代碼中注意到這一行:
command.ExecuteNonQuery();
僅被調用一次。 當您這樣做時會發生什么:
var connection = new SQLiteConnection("DataSource=:memory:;Version=3;New=True;");
connection.Open();
string sql = "CREATE TABLE recently_viewed(movieid INTEGER,picture TEXT)";
SQLiteCommand command = new SQLiteCommand(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();
}
string count_table = " SELECT count(*) FROM recently_viewed";
SQLiteCommand com3 = new SQLiteCommand(count_table, connection);
com3.ExecuteNonQuery();
int ctable = Convert.ToInt32(com3.ExecuteScalar().ToString());
Response.Write(ctable);
connection.Close();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.