开发者

SQLITE problem in rowid

开发者 https://www.devze.com 2022-12-25 13:34 出处:网络
I am using SQLite C# library andas per my requirement, before going to add I am retreving the rowid of that table.It is working fine but hetting error when table is empty. Once we add any data(a row)

I am using SQLite C# library and as per my requirement, before going to add I am retreving the rowid of that table. It is working fine but hetting error when table is empty. Once we add any data(a row) then it’s working fine .

        mDbCon  = GetConnection();
        SQLiteCommand cmd = mDbCon.CreateCommand();
        cmd.CommandTex开发者_运维技巧t = " SELECT MAX(rowid) FROM " + “MYTABLE”;
        cmd.CommandType = CommandType.Text;
        mDbCon.Open();
        SQLiteDataReader sqReader = cmd.ExecuteReader();
        while (sqReader.Read())
        {
            if ( sqReader.IsDBNull(0) )
            {
                max = (Int32)sqReader.GetInt32(0);
            }
        }
        mDbCon.Close();

It’s throwing exception when table “MYTABLE” don’t have any data.


This should work for you.

SELECT IFNULL(MAX(RowId), 1) AS Id FROM MYTABLE


try int maxRowID = Convert.Int32(cmd.ExecuteScalar());

0

精彩评论

暂无评论...
验证码 换一张
取 消