我刚开始研究c#和sql,我搜索了,但是我找不到任何解决我的问题的方法,我希望有人能帮我。我在表单上有一个DataGridView
,它是由动态创建的。我使用LINQ从数据库中得到8列。但是,我还创建了另一个列名作为“计算”,即使用其他列数据。我的问题是,我需要根据计算列过滤我的表。下面是我代码的一部分:
// get datas from database.
var query = _context.Database.SqlQuery<my_Type>("my_stored_procedure");
var binding = new BindingList<my_Type>(query.ToList());
bsMasterPrimary.DataSource = binding;
myDataGridView.DataSource = bsMasterPrimary;
//filter
DataView dv = new DataView();
dv = myDataGridView.DataSource as DataView;//dv always comes null
dv.RowFilter = string.format("Calculation <0");
// dt = (DataTable)((BindingSource)this.dgvAmazonFBAInventory.DataSource).DataSource;
我也试过了,但它犯了一个错误:
无法将类型为'System.ComponentModel.BindingList`1MyProject.MyType‘的对象强制转换为“System.Data.datTable”。}
发布于 2016-05-11 19:57:55
使用嵌套的for循环将数据网格视图的值赋值给datatable或您可以将数据转换为dataview,然后将数据视图转换为datatable更容易
https://stackoverflow.com/questions/37171683
复制相似问题