How do I count the number of rows returned in my SQLite reader in C#?

前端 未结 11 2179
生来不讨喜
生来不讨喜 2021-01-11 13:10

I\'m working in Microsoft Visual C# 2008 Express and with SQLite.

I\'m querying my database with something like this:

SQLiteCommand cmd = new SQLiteC         


        
11条回答
  •  一个人的身影
    2021-01-11 13:56

    What you request is not feasible -- to quote Igor Tandetnik, my emphasis:

    SQLite produces records one by one, on request, every time you call sqlite3_step. It simply doesn't know how many there are going to be, until on some sqlite3_step call it discovers there are no more.

    (sqlite3_step is the function in SQLite's C API that the C# interface is calling here for each row in the result).

    You could rather do a "SELECT COUNT(*) from myTable where word = '" + word + "';" first, before your "real" query -- that will tell you how many rows you're going to get from the real query.

提交回复
热议问题