【发布时间】:2014-06-16 20:32:25
【问题描述】:
我有如下客户端
Id Name status
1 A Y
2 B Y
3 C Y
4 D N
我要求仅通过SqlDataReader 检索结果并过滤它们。
这是我正在做的,
我正在执行来自 SqlDataReader 的 select 语句。
一旦结果返回到我的SqlDataReader,我就无法通过在SqlDataReader 上保留 where 子句来检索结果。
请问,我怎样才能阅读SqlDataReaderwith condition based?
SqlCommand command = new SqlCommand("SELECT ID, Name , Status FROM Client;",connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
//Here, I have to to filter the results like
//Select * from Client where status = 'N'
}
}
请推荐??
【问题讨论】:
-
请问为什么普通的 SQL WHERE 子句在这里不好?
-
这似乎是一个非常糟糕的主意。它迫使你的客户做过滤工作,而不是让数据库去做。数据库在这方面擅长:它具有索引和其他功能,可以有效地过滤数据。通过网络将整个表拉到客户端也很慢。
-
@JoelCoehoorn,我理解您的担忧。但是,在进入业务场景的下一步之前,我必须从 .Net 端进行过滤,因为我必须看到整个结果。
标签: c# .net vb.net ado.net sqldatareader