A
A
Andrew2016-07-04 13:32:25
Database
Andrew, 2016-07-04 13:32:25

Why can't get the number of rows from the table?

Hello everyone, I want to write the number of all rows of the table into a variable (at the moment there are 6 of them). But instead of 6, -1 is written. Here is the code:

private void button3_Click(object sender, EventArgs e)
        {
            command = "SELECT COUNT(*) FROM clients;";
            SQLiteCommand com1 = new SQLiteCommand(command,connection);
            connection.Open();
            count = com1.ExecuteNonQuery();
            connection.Close();
            MessageBox.Show(Convert.ToString(count));
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Nagibovich, 2016-07-04
@thebedcoder

Understand what the ExecuteNonQuery method does . In this case, it doesn't work for you. Most likely you need ExecuteScalar .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question