Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SQLDBTypes

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
gregoryagu



Joined: 12 Dec 2007
Posts: 78

PostPosted: Wed Feb 04, 2009 9:28 pm    Post subject: SQLDBTypes Reply with quote

I am loading a tree by using ADO.net, and returning a DataSet. I open the table and loop through the rows. In each row, I use code that looks like this:

String description = (string) row[0]["description'];

The issue is when the description is null. In looking into the issue on MSDN, it says to use the SqlString structure as it can handle null values.

So I changed the code to this:

SqlString description = (SqlString) row[0]["description'];

The new issue is that the field is of type string, not of type SqlString in the dataset. I know this by looking in the debugger under the column properties.

It seems that the data types of the DataTable would be of the Sql types, but this does not appear to be the case. All of the columns are using the CLR types, not the SQL data types. Do you have any idea what is up with that? I have searched and not been able to find anything on this.

My workaround is to skip using the SqlString type, and simply check for a null value before doing the conversion. Works, but its a bit kludgy. Do you know of a better way?

Thanks,

Greg
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Feb 05, 2009 5:46 am    Post subject: Reply with quote

Is this a Virtual Tree issue - or an issue with Datasets? My understanding of datasets is that for each field the DataRow stores an object. If the database entry is not null then the objects is the typed value (eg int, string) however if there is a null database entry for the row then the field value stored is actually DbNull. This can cause the type of problem you are experiencing. To avoid this you can create a function to handle the issue like:

Code:

void GetDbString(object value)
{
    return (value is DbNull) ? null : (string) value;   
}

// Then call it like
string description = GetDbString(row[0]["description"]);



If you are using typed datasets then you can set the NullValue for string fields to be (Null) and then the DataSet designer will automatically generate nice wrapper code like this:

Code:
            public string ShipAddress {
                get {
                    if (this.IsShipAddressNull()) {
                        return null;
                    }
                    else {
                        return ((string)(this[this.tableOrders.ShipAddressColumn]));
                    }
                }
                set {
                    this[this.tableOrders.ShipAddressColumn] = value;
                }
            }

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
gregoryagu



Joined: 12 Dec 2007
Posts: 78

PostPosted: Wed Feb 11, 2009 5:25 pm    Post subject: Reply with quote

Thanks very much. This was a Dataset issue, not a Virtual Tree issue. (I knew you would have an intelligent answer!)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group