When you call
ToString
on anything the system looks at the instance you are calling it on, and goes back through the inheritance chain to find the "closest" implementation. If your class explicitly implements
ToString
then taht method will be used - but if it doesn't, then the class that you are directly derived from is checked, and so on. If it can't find an explicit implementation by the time it reaches the
object
class (and remember, everything is derived from
object
in .NET) then the default implementation is used, which returns the fully qualified name of the original type.
So when you do this:
allTables[table].Add(reader.ToString());
the system checks if
SQLiteDataReader
implements
ToString
- which it doesn't. So it tries
DbDataReader
which
SQLiteDataReader
is derived from. No joy there, so back it goes - and quickly ends up at
object
, and uses the default implementation, which always returns
"System.Data.SQLite.SQLiteDataReader"
Why doesn't
SQLiteDataReader
implement
ToString
? Because it has no idea what data you do and don't want retrieved, or how you want it: it doesn't even know what the columns contain other than the very basic SQL datatypes which mostly aren't much use!
If you want to add a list of strings to a dictionary entry from a DataReader, you will have to construct a collection, and populate that yourself:
allTables[table].Add(reader["myColumn1"].ToString());
allTables[table].Add(reader["myColumn2"].ToString());
But even then, that's probably not going top do what you actually want since every column from every row will go in the same dictionary entry.
I think you want to think rather more carefully about what exactly you are trying to do with this code (and that's ignoring that you discard all the information at the end of the method anyway).
And BTW: it's considered a bad idea to use
SELECT * FROM ...
- you should always list the column names you are interested in rather than just saying "all of them".