3
Answers

where did i mistake?

Vikas Ahlawat

Vikas Ahlawat

14y
3.9k
1
I m using telerik radchart control in my window programm. below the code for populate chart. when i m using arrary then it give error , but if i simply declare chartseries then it working.

if i m using chartseries array which is show in rad color , then it gives error, and if i using green code then it working properly both code are shame only array difference.
error occuring on a[0].AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][0]));
error is: - nullreferenceexception was unhandled ,Object reference not set to an instance of an object.

SqlCommand cmd1 = new SqlCommand("select Paper1,Paper2,Paper3,Paper4,Paper5 from Student_Exams_Marks_Detail where S_ID='" + comboBox3.Text + "'and Section='" + comboBox2.Text + "' and Class='" + comboBox1.Text + "'  ", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd1);
                SqlDataAdapter da1 = new SqlDataAdapter(cmd3);
                da.Fill(ds, "Marks");
                da1.Fill(ds, "SubjectNames");
                radChart1.PlotArea.XAxis.AxisLabel.TextBlock.Text = "Years";
                //radChart1.DataSource = ds.Tables["v"];
         
                radChart3.DataSource = ds.Tables["Marks"];
                radChart4.DataSource = ds.Tables["Marks"];
                //radChart1.Skin = "LightBlue";
               
              
                radChart3.DataBind();
                radChart4.DataBind();
                


                //ChartSeries[] a;
                //a = new ChartSeries[5];
                //a[0].AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][0]));
                //a[1].AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][1]));
                //a[2].AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][2]));
                //a[3].AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][3]));
                //a[4].AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][4]));
                //a[0].Name = Convert.ToString(ds.Tables["SubjectNames"].Rows[0][3]);
                //a[1].Name = Convert.ToString(ds.Tables["SubjectNames"].Rows[0][4]);
                //a[2].Name = Convert.ToString(ds.Tables["SubjectNames"].Rows[0][5]);
                //a[3].Name = Convert.ToString(ds.Tables["SubjectNames"].Rows[0][6]);
                //a[4].Name = Convert.ToString(ds.Tables["SubjectNames"].Rows[0][7]);
                //radChart1.Clear();
                //radChart1.Series.Add(a[0]);
                //radChart1.Series.Add(a[1]);
                //radChart1.Series.Add(a[2]);
                //radChart1.Series.Add(a[3]);
                //radChart1.Series.Add(a[4]);



                ChartSeries s1 = new ChartSeries();
                ChartSeries s2 = new ChartSeries();
                ChartSeries s3 = new ChartSeries();
                ChartSeries s4 = new ChartSeries();
                ChartSeries s5 = new ChartSeries();
                s1.AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][0]));
                s2.AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][1]));
                s3.AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][2]));
                s4.AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][3]));
                s5.AddItem(Convert.ToInt32(ds.Tables["Marks"].Rows[0][4]));
                s1.Name = Convert.ToString(ds.Tables["SubjectNames"].Rows[0][3]);
                s2.Name = Convert.ToString(ds.Tables["SubjectNames"].Rows[0][4]);
                s3.Name = Convert.ToString(ds.Tables["SubjectNames"].Rows[0][5]);
                s4.Name = Convert.ToString(ds.Tables["SubjectNames"].Rows[0][6]);
                s5.Name = Convert.ToString(ds.Tables["SubjectNames"].Rows[0][7]);
                radChart1.Clear();
                radChart1.Series.Add(s1);
                radChart1.Series.Add(s2);
                radChart1.Series.Add(s3);
                radChart1.Series.Add(s4);
                radChart1.Series.Add(s5);



                radChart1.PlotArea.XAxis.AxisLabel.TextBlock.Text = "vk";

                radChart1.DataBind();

please help me what is wrong in it.
Answers (3)