locked
Using scalar query as data source for winform chart RRS feed

  • Question

  • In my winforms app i have created a dataset from Trial.Accdb database & in it i have added a Scalarquery() which return count of 1 particular column , now i want to use this query as data-source to show as a chart in my winform .Please help me how to achieve this 

    and here is form load event code

    private void FrmDashBoard_Load(object sender, EventArgs e)
            {
                
                this.mSdiesTableAdapter1.Fill(this.trialDataSet2.MSdies.);
                
    
    
                this.reportViewer1.RefreshReport();
            }

    Thursday, August 6, 2020 6:08 AM

Answers

  • Hi Ravi Kumar,
    First, I made a test by following your steps:
    There are some screenshots and test code below.
    Note that you need to choose "SELECT which returns rows".
    Screenshots:


    Here is a simple code example:

    private void Form1_Load(object sender, EventArgs e)
    {
        testTableAdapter.ScalarQuery(my_DatabaseDataSet1.test);
        chart1.DataSource = my_DatabaseDataSet1.Tables[0];
    
        //Mapping a field with x-value of chart
        chart1.Series[0].XValueMember ="Id";
    
        // Mapping a field with y-value of Chart
        chart1.Series[0].YValueMembers ="Expr1";
    
        //Bind the DataTable with Chart
        chart1.DataBind();
    }

    The result:


    Best Regards,
    Daniel Zhang


    "Windows Forms General" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Windows Forms General" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Friday, August 7, 2020 6:30 AM

All replies

  • Hi Ravi Kumar,
    First, I made a test by following your steps:
    There are some screenshots and test code below.
    Note that you need to choose "SELECT which returns rows".
    Screenshots:


    Here is a simple code example:

    private void Form1_Load(object sender, EventArgs e)
    {
        testTableAdapter.ScalarQuery(my_DatabaseDataSet1.test);
        chart1.DataSource = my_DatabaseDataSet1.Tables[0];
    
        //Mapping a field with x-value of chart
        chart1.Series[0].XValueMember ="Id";
    
        // Mapping a field with y-value of Chart
        chart1.Series[0].YValueMembers ="Expr1";
    
        //Bind the DataTable with Chart
        chart1.DataBind();
    }

    The result:


    Best Regards,
    Daniel Zhang


    "Windows Forms General" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Windows Forms General" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Friday, August 7, 2020 6:30 AM
  • Hello sir ..Thank you very very much...i am really grateful to you ..do you conduct any tutorials or course sir ? if so please tell me i will join.
    Friday, August 7, 2020 11:02 AM
  • Hi Ravi Kumar,
    I am glad that your problem has been solved, and it is my pleasure to help you solve problems.
    Best Regards,
    Daniel Zhang


    "Windows Forms General" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Windows Forms General" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Monday, August 10, 2020 8:34 AM