Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Highlighted
Silver Contributor
Posts: 835
Registered: ‎03-24-2009

datareader IsDbNull handling

Using a datareader which is returning rows with counts and sums.....of course a sum could be a null data type....

 

I do know the 'field' name......and the field column ordinal number

Am I getting close with the // stuff? below?

 

                        while (reader.Read())
                        {
                            // Create an array big enough to hold the column values
                            object[] values = new object[reader.FieldCount];
                            // Get the column values into the array
                            reader.GetValues(values);
//if(!reader.IsDBNull(7))
//{
// use (string)reader[7]
//} else we need to return a '0'
                            // Add the array to the ArrayList
                            results.Add(new Sage.Platform.ComponentModel.ComponentView(propertyPaths, values));
                        }

 

 

Thanks!

 

 

 

RJ Samp
Highlighted
Silver Contributor
Posts: 835
Registered: ‎03-24-2009

Re: datareader IsDbNull handling

Solution:

 

                        // Get the column values into the array
                            reader.GetValues(values);
                            // Get rid of Null values in the datareader returned array:
                            if(reader.IsDBNull(6))
                            {
                                values[6] = "0";
                            }
                            if(reader.IsDBNull(7))
                            {
                                values[7] = "0";
                            }
                            if(reader.IsDBNull(8))
                            {
                                values[8] = "0";
                            }
                            // Add the array to the ArrayList
                            results.Add(new Sage.Platform.ComponentModel.ComponentView(propertyPaths, values));
  

 

RJ Samp