Sign in to follow this  
Guest Basundhara Ghosal

Problems with database to chart

Recommended Posts

I am trying to pull a simple database:

tring connString = "Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Inf_Cap.mdf;Integrated Security=True;User Instance=True";
// OLD LINK Data Source=HECND7261TRBSQLEXPRESS;database=TestDatabase; UID=dbtest;PWD=87JamesH
string strSQL = "SELECT TOP 5 Date AS Date, Used_Cap AS Used_Cap, Available_Cap " +
"FROM Inf_Cap_Monthly " +
"ORDER BY Date Desc " +
"FOR XML AUTO";
SqlConnection objConnect = new SqlConnection(connString);
objConnect.Open();
SqlCommand objCommand = new SqlCommand(strSQL, objConnect);
SqlDataReader myReader = objCommand.ExecuteReader();
StringBuilder xmlData = new StringBuilder();
xmlData.AppendFormat("<chart caption='Infrastructure Capacity Usage' subCaption='Monthly' xAxisName='Month' yAxisName='% Used' showValues='0' formatNumberScale='0' showBorder='1'>");
while (myReader.Read())
{
xmlData.AppendFormat("<set label='{0}' value='{1}' />", myReader["Date"].ToString(), myReader["Used_Cap"].ToString());
}
myReader.Close();
xmlData.Append("</chart>");
//Create the chart with data from xmlData
Literal1.Text = FusionCharts.RenderChartHTML("../FusionCharts/Column3D.swf", xmlData.ToString(), "", "myFirst", "600", "300", false);
objConnect.Close();
objConnect.Dispose();
}
}
}

First is the code even all i need? Second i get a indexoutofrange exception in this area:

while (myReader.Read())
{
xmlData.AppendFormat("<set label='{0}' value='{1}' />", myReader["Date"].ToString(), myReader["Used_Cap"].ToString());
}

Thanks

Ben

Share this post


Link to post
Share on other sites
Guest Basundhara Ghosal

Hi,

Thanks for your reply and sharing your idea.

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