Jamie Keeling
Jamie Keeling

Reputation: 9966

SQLite Select statement returns nothing - C#

Fairly simple problem, I have a table in a database that contains one column and fourteen rows.

When trying to return all of the rows in the database I try the following:

command = new SQLiteCommand("SELECT Value FROM Currency", connection);

Yet when I look at the amount of results affected (And the lack of elements in my array) I notice the following:

Huh

Apparently there's nothing in there, I've even checked with two seperate tools that confirm the data is in there. Am I executing this incorrectly? I simply want to iterate over the values returned and store them in an array.

Thanks for your time! Edit:

Solution!

int i = 0;
while (dReader.Read())
{  
    _data[i] = Convert.ToSingle(dReader[0]);
    i++;     
}

This works fine :)

Upvotes: 0

Views: 2200

Answers (2)

Bala R
Bala R

Reputation: 108957

SqlDataReader.RecordsAffected is not affected for select queries.

Gets the number of rows changed, inserted, or deleted by execution of the Transact-SQL statement.

EDIT:

while ( dReader.Read() )
{
    Console.WriteLine("Value " + dReader[0]);
}

Upvotes: 4

Ryan
Ryan

Reputation: 28187

Shouldn't you be doing a

 while ( dReader.Read() )
{
    ....
}

to loop through your resultset?

Upvotes: 2

Related Questions