lundi 30 mars 2015

SQLiteDataAdapter converts null to 0 - how to prevent that?

Below is a snippet of the code. As you can see, that method returns a table from SQLite database, and adds that table to a DataSet if it doesn't exist yet.



SQLiteConnection connection;
DataSet Set = new DataSet();

DataTable GetTable(string tableName, string command)
{
if (!Set.Tables.Contains(tableName))
{
var adapter = new SQLiteDataAdapter(command, connection);
SQLiteCommandBuilder builder = new SQLiteCommandBuilder(adapter);

adapter.FillSchema(Set, SchemaType.Source, tableName);
adapter.Fill(Set, tableName);
adapter.Dispose();
}

return Set.Tables[tableName];
}


To call it, for example



DataTable myTable = GetTable("MyTable", "select * from MyTable);


There are some cells that are of type int/decimal, but their values are null. However when I'm trying to populate myTable, they are conveniently converted to 0's which I DO NOT WANT. How do I go about fixing that? I would like to keep null values as null's.


The SQLite file that I use is SQLite3. Just in case it helps.


Thanks in advance!


Aucun commentaire:

Enregistrer un commentaire