tags:

views:

11

answers:

1

I am trying to create a form where the user can view data from the database in a datagrid view. I want the user to be able to choose like the time period from which to start from in one combobox cmbDate and the period to in another combobox cmbDateTo.I have written the following code:

namespace linqToSql_trial { public partial class frmMonthlyOperatorStatistics : Form { private userLoginDataContext dc;

    public frmMonthlyOperatorStatistics()
    {
        InitializeComponent();
        dc = new userLoginDataContext();
    }

    private void LoadData()
    {
        cmbDate.DataSource = dc.dailyOperatorStatistics.Select(x=>x.date);

        cmbDate.DisplayMember = "date";
        cmbDate.ValueMember = "date";
    }

    private void LoadDateTo()
    {
        cmbToDate.DataSource = from to in dc.dailyOperatorStatistics
                               select to;
        cmbToDate.DisplayMember = "date";
        cmbToDate.ValueMember = "date";

    }

    private void btnLoad_Click(object sender, EventArgs e)
    {
        this.operatorStatDataGridView.DataSource = dc.dailyOperatorStatistics.Where(x => x.date >= Convert.ToDateTime(cmbDate.SelectedItem) && <= Convert.ToDateTime(cmbToDate.SelectedItem));
    }

    private void frmMonthlyOperatorStatistics_Load(object sender, EventArgs e)
    {
        LoadData();
        LoadDateTo();
    }

} } It is generating errors on the button clicking method via the part <= Convert.ToDateTime(cmbToDate.SelectedItem));

A: 

I have managed to get a solution to this and I simply wrote the following code in the btnLoad_clik method.

this.operatorStatDataGridView.DataSource = dc.dailyOperatorStatistics.Where(x => x.date >= Convert.ToDateTime(cmbDate.SelectedItem) && x.date <= Convert.ToDateTime(cmbToDate.SelectedItem));

and changed the loadToDate method to this

private void LoadDateTo() { cmbToDate.DataSource = dc.dailyOperatorStatistics.Select(x=>x.date); cmbToDate.DisplayMember = "date"; cmbToDate.ValueMember = "date";

    }

this has been able to give me the required results.

Allan