日期:2014-05-20 浏览次数:20649 次
StartLinqDataContext start = new StartLinqDataContext(); private void button1_Click(object sender, EventArgs e) { var chaxun = from c in start.FeeMain select new { c.remark4,c.indatatime,c.wtdw,c.vessel,c.voyage,c.blno,c.accounts,c.pay,c.profit }; if (cmb_wtdw.Text != "") chaxun = chaxun.Where(c => c.wtdw == cmb_wtdw.Text); chaxun = chaxun.Where(c => Convert.ToDateTime(c.indatatime) >=Convert.ToDateTime( dtp1.Value.ToString("yyyy/MM/dd 00:00:00")) &&Convert.ToDateTime( c.indatatime) <=Convert.ToDateTime( dtp2.Value.ToString("yyyy/MM/dd 23:59:59"))); dataGridView1.AutoGenerateColumns = false; dataGridView1.DataSource = chaxun.ToList(); var list = new List<FeeMain>(); list.AddRange(dataGridView1.DataSource as List<FeeMain>);//报错 值不能为空 list.Add(new FeeMain()); dataGridView1.DataSource = list; }