Last post Apr 17, 2008 09:11 PM by nikki_doer_of_things
Apr 17, 2008 08:47 PM|dvd.ribeiro|LINK
I have a C# DataTable which I want to pass into a method, which receives an object. Something like this:
this.setData.("pTable",dt); //dt is my local DataTable and I can asure it has data (proved on Debug and Trace), pTable is the object where I want to store the DataTable
//setData - receives key (identifier) and object, the object must be the DataTable
private void setData(string key, object value)
if (value == null || value.ToString() == "")
The purpose is to serialyze the DataTable, however this setData method already does that 100% to Hashtable. When I pass the dt to this method, it is given with data, but when the setData method tests the condition "value == null || value.ToString() == "",
it has null value.
I've already tried to cast the object, giving (DataTable)dt as parameter, however, no luck. Tried also dt.Copy(), dt.Clone().
Is there anything I'm not doing well or missing here?
Thanks for your support, good coding.
Apr 17, 2008 09:11 PM|nikki_doer_of_things|LINK
ToString of most objects will simply be the type. It isn't "" except for real strings (and other objects that override ToString in order to get that behavior).
If you want a generic method, you are probably best off making it a real Generic method that takes <Type T > and casting appropriately using Type Of or Is operator. The way to test a data table is to see if the Rows.Count > 0, most of the time, so you'd
handle it differently than a Hashtable or other Collection.