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

前端 未结 11 2158
生来不讨喜
生来不讨喜 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 14:05

    Try this,

    SQLiteCommand cmd = new SQLiteCommand(conn);
    
    cmd.CommandText = "select id from myTable where word = '" + word + "';";
    
    SQLiteDataReader reader = cmd.ExecuteReader();
    
    while (reader.HasRows)
    
         reader.Read();
    
    int total_rows_in_resultset = reader.StepCount;
    

    total_rows_in_resultset gives you the number of rows in resultset after processing query

    remember that if you wanna use the same reader then close this reader and start it again.

提交回复
热议问题