我想創建一個窗體,用戶可以在數據網格視圖中查看數據庫中的數據。我希望用戶能夠選擇喜歡從哪個開始的時間從一個組合框中cmbDate,週期到另一個組合框cmbDateTo.I寫了下面的代碼:在數據網格視圖中顯示定期的自定義數據
命名空間linqToSql_trial { 公共部分類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();
}
} } 它通過部分生成上的按鈕點擊方法錯誤< = Convert.ToDateTime(cmbToDate.SelectedItem));