0

I have a asp.net page in which I have a chart that I dragged on from the toolbox designer. I know that if I click on this chart, a "chart tasks" menu will appear so that I can define the sql data source, chart type and x&y values. The problem I am having is that my sql data source requires user input. I want the user to input a date and search records based on the input date. Therefore, I cant define an sql query on the chart tasks menu because it will tell me that my query is invalid. My code looks like this so far:

con1.Open();
    SqlCommand cmd2 = new SqlCommand (string.Format ("select CustomerName, AccountNumber,  DateReading, Time, ID from dbo.NewLogTable join dbo.CustomerTable on ID = Customer_ID join dbo.VoltageTable on Voltage_Reading = Provided_Voltage where Sensor_ID = 'FA0009' and DateReading= '{0}' " ,TextBox1.Text), con1);
    SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
    DataSet ds2 = new DataSet();
    da2.Fill(ds2);
    Chart2.DataSource = da2;
    Chart2.Visible = true;
    Chart2.DataBind();

    con1.Close();

whenever I input the date and click the button, nothing happens. I know the sqlCommand is correct. However, I can not find a way to set the x and y values for my chart. I tried Chart2.Xvalue and .parameters and cant find a way to set those. I think that is whats giving me trouble. Can anyone shed some light on this issue? Thanks.

1 Answer 1

1

Use:

You have to assign DataSet ds2 as DataSource for your chart instead of using SqlDataAdapter da2.

Chart2.DataSource = ds2;

instead of

Chart2.DataSource = da2;
Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your response. I see the change you have made and it makes sense. However, I still don't have a way to set my x & y parameters. Also, I am still not even seeing my graph even though I have set visible to true.
@Rick once you have assigned the datasource, you need to Databind() it for the data to display. Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.