How to get single values from DataSet

Jai Prakash asked on September 30, 2014 15:07

Hi,

I am using below query to fetch single integer value. Query is 100% right. but getting "Object reference not set to an instance of an object."

DataSet Panes = new DataQuery("custom.challenge.AccordionPanes") .Columns("Panes") .Where("challenge.NodeID", QueryOperator.Equals, 45894) .Execute();

I am trying to get value from syntax

string panesValue = (string)Panes.Tables[0].Rows[0][0];

But getting "NullReferenceException: Object reference not set to an instance of an object."

Please help ?

Recent Answers


Joshua Adams answered on September 30, 2014 18:16

Are you doing this in a foreach statement?

foreach(DataRow r in Panes.Tables[0].Rows)
{
    string panesValue = ValidationHelper.GetString(r["ColumnName"], "" );
    //perform action with value
}
1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 30, 2014 22:18

On top of what Josh mentions you might also do a check to see if the dataset is empty

if(!DataHelper.IsEmptyDataSet(Panes))
{
    // do your work
}
1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.