none
C# TableAdapter Query a Access DB with values from Timedatepicker using both a Start and End Date RRS feed

  • Question

  • I am trying to build a program in C# using a TableAdapter Query to a Access DB with values from Timedatepicker with both a Start and End Date

    My StartDate value comes from my TimeDatePicker named StartDate and EndDate value comes from my TimeDatePicker named EndDate

    namespace ScoreCardReport
    {
        public partial class Form1 : Form
        {
            OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\PBPLRA148ZLN1\ScoreCard\Score.accdb;Persist Security Info=True;Jet OLEDB:Database Password=123456");

            public Form1()
            {

            }
            private void reportViewer1_Load(object sender, EventArgs e)
            {
            }

            private void bUpdate_Click(object sender, EventArgs e)
            {
                vcon.Open();

                DateTimePicker StartDate = new DateTimePicker();
                DateTimePicker EndDate = new DateTimePicker();
                this.ScoreTableAdapter.Fill(this.scoreDataSet.Score);
                this.reportViewer1.RefreshReport();

                vcon.Close();
            }

          


        }
    }

    In my TableAdapter Configureation Wizard I have 

    SELECT        *
    FROM            Score 
    WHERE       
    BETWEEN TimeDate >= #StartDate# AND #EndDate#

    Error = Generated SELECT statement 

    Unable to Parse Query Text.

    a bunch of other queries but i get an error every time.  

    When I do get it to not have errors, it still doesnt work because the ScoreTableAdapter  because "FILL,GetData()"  stays the same and doesnt have Fill,GetData(vaules) like have seen in other quries.

    Sincerely,

    Mark Lombardi

    Tuesday, November 19, 2013 3:46 PM

Answers

  • Hello,

    Have a try to change the query to be like below:

    SELECT        OrderDetailID, OrderDetailCode, OrderDetailName, OrderID, DataTime

    FROM            OrderDetail

    WHERE        (DataTime BETWEEN @StartDate AND @EndDate)

    To use the ‘between … and …’ combination or use the ‘>= <=’ combination like below:

    SELECT        OrderDetailID, OrderDetailCode, OrderDetailName, OrderID, DataTime

    FROM            OrderDetail

    WHERE        (DataTime >= @StartDate) AND (DataTime <= @EndDate)

    Do not to mix them.

    And when to call the method, we need to pass the parameters like below:

    DataSet1 ds = new DataSet1();
    
    
                OrderDetailTableAdapter orderDetailTableAdapter = new OrderDetailTableAdapter();
    
    
                DateTime startDate = new DateTime(2013, 1, 1);
    
    
                DateTime endDate = new DateTime(2014, 1, 1);
    
    
                this.dataGridView1.DataSource = orderDetailTableAdapter.GetData(startDate, endDate);
    

    And for more information regarding TableAdapter please have look at the link below:

    http://msdn.microsoft.com/en-us/library/ms171905(v=vs.110).aspx

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 20, 2013 4:29 AM
    Moderator