locked
SQL Parameter with Charting RRS feed

  • Question

  • User937573798 posted

    Hi there.

    My chart is not rendering when adding parameter. Am I missing something?

        private void populateChartByTypes()
        {
                String strConnString = ConfigurationManager.ConnectionStrings["ohYeah"].ConnectionString;
                String strQuery = "SELECT SR_SUB_TYPE_CSR, Count(SR_SUB_TYPE_CSR) as TypeTotal FROM CSP_GLOBAL_CLOSED_2011 WHERE DESCRIPTION_CLEAN LIKE '%@DESCR%' GROUP BY SR_SUB_TYPE_CSR ORDER BY TypeTotal DESC ";
                SqlConnection con = new SqlConnection(strConnString);

                SqlCommand cmd = new SqlCommand(strQuery);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@DESCR", txtTag.Text);
                Chart2.DataSource = cmd;
                Chart2.AlignDataPointsByAxisLabel();
                Chart2.Series["Series1"].ChartType = SeriesChartType.Column;
                Chart2.Series["Series1"].IsValueShownAsLabel = true;
                Chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Angle = -60;
                Chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Interval = 1;
                Chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsEndLabelVisible = true;
                Chart2.ChartAreas["ChartArea1"].Area3DStyle.IsRightAngleAxes = true;
                Chart2.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = false;
                Chart2.Series["Series1"].XValueMember = "SR_SUB_TYPE_CSR";
                Chart2.Series["Series1"].YValueMembers = "TypeTotal";
                Chart2.DataBind();        
        }

    Cheers

    Wednesday, June 15, 2011 7:52 AM

Answers

  • User937573798 posted

    RESOLVED !

    cmd.Parameters.Add("@TAG", SqlDbType.NVarChar).Value = txtTag.Text;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 15, 2011 11:53 AM

All replies

  • User1648350404 posted

    Use SqlDataAdapter to create a new DataTable, let's suppose it's called "dt".

    then try this:

     Chart2.Series["Series1"].Points.Clear();

    foreach(DataRow row in dt.Rows)

    {...

        Chart2.Series["Series1"].Points.Add(value1,value2...);  

    ..

    }

    Wednesday, June 15, 2011 8:23 AM
  • User937573798 posted

    Thanks for your quick answer. Could you please further help me out with exact code. It's becoming one mash-up in my head.

    Wednesday, June 15, 2011 10:03 AM
  • User937573798 posted

    RESOLVED !

    cmd.Parameters.Add("@TAG", SqlDbType.NVarChar).Value = txtTag.Text;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 15, 2011 11:53 AM