tags:

views:

30

answers:

1

I am trying to create an application where I want a data grid view to display the data depending on the date that the user selects in the combo box i.e.cmbDate according to my application. The cmbDate displays the available dates in the database. Below is my source code that I have written but on debugging the compiler gives an error of operator '==' cannot be used to compare 'System.DateTime' and 'object'. I would want that when the user clicks the load button it loads data for the date or month chosen.

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

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

        private void LoadDate()
        {
            cmbDate.DataSource = dc.flights.Select(x=>x.date);

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

        private void frmSample_Load(object sender, EventArgs e)
        {
            LoadDate();
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {

           this.flightsDataGridView.DataSource = dc.flights.Where (x => x.date == cmbDate.SelectedItem);

        }
    }
}
+5  A: 

Error is coming because you need to convert your selected item in DATETIME

for example

this.flightsDataGridView.DataSource = dc.flights.Where (x => x.date == Convert.ToDateTime( cmbDate.SelectedItem));

this may resolve your problem

Pranay Rana
Hi Thanx It worked.
Allan
as i informed you accept the answer becuase your accpetance rate it 0%
Pranay Rana