User-158363518 posted
hi every body
how i can resolve this error ?
{
I want all
the chart data, read from the database.
Such as categories .
I want to show
persian date (Hijri Shamsi) in category.
Thank You Very Much
}
Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
error Line 89 :
chrtMyChart.Text = chart.ToHtmlString();
protected string constring = WebConfigurationManager.ConnectionStrings["chart"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
Render_Chart();
}
protected void Render_Chart()
{
SqlConnection myConn = new SqlConnection(constring);
//get count of result //
int countersel = 0;
string counter = "SELECT COUNT(*) FROM GradeList where idStudent='11111111111'";
SqlCommand mycounter = new SqlCommand(counter, myConn);
myConn.Open();
SqlDataReader dr1 = mycounter.ExecuteReader();
if (dr1.Read())
{
countersel = int.Parse(dr1.GetValue(0).ToString());
}
myConn.Close();
////
string commandText = "SELECT dateGrade, grade FROM GradeList where idStudent='11111111111'";
SqlCommand myComm = new SqlCommand(commandText, myConn);
myConn.Open();
SqlDataReader reader = myComm.ExecuteReader();
Object[] chartValues = new Object[countersel];
string [] dates = new string [countersel];
if (reader.HasRows)
{
int i = 0;
while (reader.Read())
{
chartValues[i] = reader.GetValue(1);
i++;
}
int b = 0;
while (reader.Read())
{
dates[b] = reader.GetValue(0).ToString();
b++;
}
}
else
{
Console.WriteLine("No rows found.");
}
reader.Close();
myConn.Close();
DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart")
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
.SetTitle(new Title
{
Text = "Monthly Scores",
X = -20
})
.SetSubtitle(new Subtitle
{
Text = "scores",
X = -20
})
.SetXAxis(new XAxis
{
Categories = dates
})
.SetSeries(new[]
{
new Series { Name = "Csajad", Data = new Data(chartValues)}
});
chrtMyChart.Text = chart.ToHtmlString();
}