views:

632

answers:

2

Hello, I'm attempting to pull some data from a SQLite database so that I can populate a GridView in my GUI: here is the code that returns the DataTable:

DataTable table = new DataTable();

SQLiteDataAdapter adapter = new SQLiteDataAdapter(this.command.CommandText, this.connection);
adapter.Fill(table);

return table;

For some reason after calling adapter.Fill, the DataTable is still not populated with anything. So far I've verified that the command text is correct and that the connection contains the correct connection string. Both are used successfully in other parts of the application. No exceptions seem to be thrown... Is there any place else I should be looking for trouble? Am I using the API incorrectly?

Thanks!

A: 

Is there a constructor that lets you just pass in the command directly?

Alex Beynenson
There is no such constructor for either DataTable or DataGridView. Is this what you meant?
sweeney
I am guessing he means to the Adapter constructor.
CSharpAtl
The adapter constructor does consume the command directly. It's the first argument.
sweeney
+1  A: 

This looks like correct usage.

One thing to check -- after the fill you say the datatable is not populated. Were you just checking Rows.Count? What about columns? If the Fill creates columns to match your SELECT statement, but there aren't any rows, then you know the code is working but there's a problem with either your query, or you're not hitting the same database you think you are.

Clyde
Well I'll be damned. The DataTable IS being populated, I just wasn't looking at the right members in the QuickWatch: Columns were correctly being loaded and a number of rows were returned. This does not really solve my underlying problem however your advice has led me to understand the problems lie elsewhere.
sweeney
@sweeny what was the REAL problem? I'm getting similar errors so if solved it please kindly let us know.
Lirik