SQLite Select Where ID Equals

本文关键字:Equals ID Where Select SQLite | 更新日期: 2023-09-27 18:08:15

我正在尝试在sqlite数据库中创建父子层次结构。
但是,在最后一行

之前的行出现了异常。
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();

SQLite Select Where ID Equals

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
            }
        }
    }
}