如何正确返回和处理数据集的数据视图 - 看到奇怪的结果
我试图弄清楚如何正确返回数据视图。我注意到,如果我绑定到下面使用的结果数据视图,我不会得到任何结果。
private DataView filterDocuments(DataSet documents, string classType)
{
using (documents)
{
//filter it
using (DataView documentsByType = new DataView(documents.Tables[0], String.Format("ClassName = '{0}'", classType), String.Empty, DataViewRowState.CurrentRows))
{
return documentsByType;
}
}
}
但是,如果我不处理我的数据视图,我可以看到我想要的结果。如何正确返回数据视图?
private DataView filterDocuments(DataSet documents, string classType)
{
using (documents)
{
//filter it
return new DataView(documents.Tables[0], String.Format("ClassName = '{0}'",classType), String.Empty, DataViewRowState.CurrentRows);
}
}
我不需要丢弃它吗?我是否造成了内存泄漏?我必须通过引用传递数据集吗?
非常感谢!
I'm trying to figure how to correctly return a dataview. I noticed that if I bind to the resultant dataview used below, I don't get any results.
private DataView filterDocuments(DataSet documents, string classType)
{
using (documents)
{
//filter it
using (DataView documentsByType = new DataView(documents.Tables[0], String.Format("ClassName = '{0}'", classType), String.Empty, DataViewRowState.CurrentRows))
{
return documentsByType;
}
}
}
However, if I don't dispose of my dataview, I can see teh results I want. How can I properly return a dataview?
private DataView filterDocuments(DataSet documents, string classType)
{
using (documents)
{
//filter it
return new DataView(documents.Tables[0], String.Format("ClassName = '{0}'",classType), String.Empty, DataViewRowState.CurrentRows);
}
}
Do I not need to dispose of it? Am I creating a memory leak? Do I have to pass the dataset by reference?
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
using
(或调用DataView.Dispose()
)的正确位置是您使用DataView
的位置。它并不在这个地方处理它是有意义的。The correct place for the
using
(or callingDataView.Dispose()
would be wherever you are making use of theDataView
. It doesn't make sense to dispose of it in this spot.