我正在尝试在sqlite数据库中创建一个Parent-Child层次结构 但是,我在最后一行之前的那一行得到了一个例外
An unhandled exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dll
Additional information: SQL logic error or missing database
这是我的代码:
SQLiteDataReader reader;
string main_subject = "";
lastParagraphHeading2 = false;
sql = "SELECT last_insert_rowid() FROM Hilchot";
command = new SQLiteCommand(sql, m_dbConnection);
long lastID = (long)command.ExecuteScalar();
sql = "select * from Hilchot where ID=" + lastID;
command = new SQLiteCommand(sql, m_dbConnection);
reader = command.ExecuteReader();
main_subject = reader["Title"].ToString();
答案 0 :(得分:-1)
using (var connection = new SQLiteConnection())
{
connection.ConnectionString = connectionString;//your connection string here
using (var command = new SQLiteCommand())
{
connection.Open();
command.CommandType = CommandType.Text;
command.CommandText = sql;
command.Connection = connection;
using (SQLiteDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
// Do something
}
}
}
}