Sign in to follow this  
Rahul Kumar

Problem with Nulls

Recommended Posts

Code is below.It works fine except when there are nulls, we then get the dreaded

Object reference not set to an instance of an object.

///THIS IS THE CODE

 

public string GetManagementControls()

{

StringBuilder xmlData = new StringBuilder();

//Generate the chart element

xmlData.Append(

"<chart caption='' subCaption='RISK SCORES ' pieSliceDepth='30' showBorder='0'useRoundEdges = '1' formatNumberScale='0' connectNullData='0' numberSuffix=''>");

string factoryQuery = "SELECT AVG(CAST(SQone.SQoneScore2 AS INT)) as TotQ FROM SQone ";

DbConn oRs = new DbConn(factoryQuery);

//Iterate through each record

while (oRs.ReadData.Read())

{

String LableActivity = " ";

LableActivity =

" Documentation";

xmlData.AppendFormat(

"<set label='{0}' value='{1}' />", LableActivity, oRs.ReadData["TotQ"].ToString());

//xmlData.AppendFormat("<set label='{0}' value='{1}' />", (oRs.ReadData["LocationName"].ToString()), oRs.ReadData["ImpairScore"].ToString());

//xmlData.AppendFormat("<set label='{0}' value='{1}' />", oRs.ReadData["Complete"].ToString(), oRs.ReadData["TotQ"].ToString());

}

oRs.ReadData.Close();

//Close chart element

xmlData.Append(

"</chart>");

//Create the chart - Pie 3D Chart with data from xmlData

return FusionCharts.RenderChart("../FusionCharts/Bar2D.swf?noCache=2", "", xmlData.ToString(), "FactorySum2", "600", "300", false, false);

}

Share this post


Link to post
Share on other sites

Hi,

Could you please use the following code and try again?

if (!oRs.ReadData["TotQ"].Equals(System.DBNull.Value))
{
xmlData.AppendFormat("<set label='{0}' value='{1}' />", LableActivity, oRs.ReadData["TotQ"].ToString());
}
else
{
xmlData.AppendFormat("<set label='{0}' value='0' />", LableActivity);
}

Share this post


Link to post
Share on other sites
Guest Basundhara Ghosal

Hi,

You are most welcome.

Thanks for your kind words.

We are glad that your issue is resolved.

Keep smiling and keep FusionCharting. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this