c# BindingSource.Filter为什么没有生效

blade3658 2009-03-11 11:06:45

computerBindingSource.DataSource = sql.Computer;
this.computerBindingSource.Filter = "CID=1"; //列出了所有的行,这句没有生效,CID字段名是INT型
this.computerBindingSource.Sort = "CID DESC"; //这句生效了,CID字段名应该是正确的

换一个字段再试试
computerBindingSource.DataSource = sql.Computer;
computerBindingSource.Filter = "Users=\'AAA\'"; //换成字符型字段也不行,还是列出所有行
computerBindingSource.Sort = "Users"; //排序是生效了
...全文
1057 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanxi 2010-09-14
  • 打赏
  • 举报
回复
楼上的解答我测试过了,完全可行。只是后面书写应为:{return obj.Users=="AAA";}
实例代码如下:
public List<Model.MonitorInfo> BrowseMonitorDataByMeasureType(List<Model.MonitorInfo> monitorData, string measureType)
{
List<Model.MonitorInfo> subMonitorData = monitorData.FindAll(delegate(Model.MonitorInfo obj) { return obj.MeasureType == measureType; });
return subMonitorData;
}
wangping_li 2009-03-11
  • 打赏
  • 举报
回复
是的话直接把sql.Computer进行筛选后再给bindingsource
sql.Computer=sql.Computer.FindAll(delegate(sql.Computer的类型 obj){return obj.Users='AAA';});
wangping_li 2009-03-11
  • 打赏
  • 举报
回复
sql.Computer这个类型是什么,是不是List<Computer>?
wangping_li 2009-03-11
  • 打赏
  • 举报
回复
computerBindingSource.Filter ="Users='AAA'";
wangping_li 2009-03-11
  • 打赏
  • 举报
回复

// Create the connection string, data adapter and data table.
SqlConnection connectionString =
new SqlConnection("Initial Catalog=Northwind;" +
"Data Source=localhost;Integrated Security=SSPI;");
SqlDataAdapter customersTableAdapter =
new SqlDataAdapter("Select * from Customers", connectionString);
DataTable customerTable = new DataTable();

// Fill the the adapter with the contents of the customer table.
customersTableAdapter.Fill(customerTable);

// Set data source for BindingSource1.
BindingSource1.DataSource = customerTable;

// Filter the items to show contacts who are owners.
BindingSource1.Filter = "ContactTitle='Owner'";

// Sort the items on the company name in descending order.
BindingSource1.Sort = "Country DESC, Address ASC";

// Set the data source for dataGridView1 to BindingSource1.
dataGridView1.DataSource = BindingSource1;



说明Filter写法是正确的,再仔细检查下,是不是有别的原因
blade3658 2009-03-11
  • 打赏
  • 举报
回复
还是不行,又弄了一会儿
computerBindingSource.DataSource = sql.Computer;
computerBindingSource.Filter = @"Users='AAA'";
computerBindingSource.Sort = "Users";
label1.Text+=computerBindingSource.SupportsFiltering.ToString();//这里这个属性是false,不支持筛选?

其它代码是由O/R设计器生成LINQ to SQL类,来读取数据库的,问题是不是出在这里?
wuyq11 2009-03-11
  • 打赏
  • 举报
回复
this.computerBindingSource.Filter = "CID='1'";
guanmingle 2009-03-11
  • 打赏
  • 举报
回复
试试datagridview.RowFilter="CID=1";

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧