Could you not do something like this to handle the nullable types? T GetValue<T>(string field) { object obj = reader[field];
if (obj is System.DBNull) return default(T); else return (T)obj; } Assuming the type is nullable, it should do the right thing, and if it's an unexpected type, it'll throw an exception when casting to T. On Mon, Jul 14, 2014 at 4:07 PM, Edward Ned Harvey (sqlite) < sql...@nedharvey.com> wrote: > I understand there are only 5 data types in Sqlite, and that the column > type isn't necessarily the type of object returned in a query. Is there a > more seamless way to cast responses than this? > > I would really love to have an easy way of putting a long? into the > database, and then getting a long? back out. Maybe it exists and I'm just > doing it the hard way right now... > > string employeeName; > > object myObj = reader["employeeName"]; > if (myObj is System.DBNull) > employeeName = null; > else if (myObj is string) > employeeName = (string)myObj; > else > throw new Exception("Unexpected object type"); > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users