如何检测数据源的第一个或最后一个 [英] How to detect the first or last of datasource
本文介绍了如何检测数据源的第一个或最后一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
以前当我用delphi开发以检测最后一个数据源列表作为我的循环条件时我正在编写
当(MyDataSet.MyDataSource.eof)做
开始
结束;
,现在如何在C#中做同样的事情
谢谢
解决方案
看看这是否有帮助,如果没有,那么回答错误或没有意义。
数据这里的来源是
DataTable 在
DataSet 中。 BindingSource组件提供了很大的灵活性,使用System;
使用System.Data;
使用System.Windows.Forms;
名称空间C6_Features
{
公共类Class1
{
private BindingSource bs = new BindingSource();
private DataSet ds;
public Class1()
{
ds = new DataSet();
// TODO填充数据集中的一个或多个表
bs.DataSource = ds.Tables [0];
}
public void datasetDemo()
{
bs.MoveLast(); //你现在在最后一行
bs.MoveFirst(); //回到第一行
//迭代所有行
foreach(ds.Tables [0] .Rows中的DataRow行)
{
Console.WriteLine(
" {row.Field<串GT;(" SomeField")}");
}
}
}
}
Hi all,
Formerly when i was developing by delphi in order to detect the last of datasource list as my loop condition i was writing
When(MyDataSet.MyDataSource.eof)do
Begin
end;
, now how can do the same in C#
Thanks
解决方案
See if this might help, if not then responded with what is wrong or does not make sense.
The data source here is a DataTable in a DataSet. The BindingSource component offers a good deal of flexibility,
using System; using System.Data; using System.Windows.Forms; namespace C6_Features { public class Class1 { private BindingSource bs = new BindingSource(); private DataSet ds; public Class1() { ds = new DataSet(); // TODO populate one or more tables in the dataset bs.DataSource = ds.Tables[0]; } public void datasetDemo() { bs.MoveLast(); // you are now at the last row bs.MoveFirst(); // back to the first row. // iterate all rows foreach (DataRow row in ds.Tables[0].Rows) { Console.WriteLine(
"{row.Field<string>("SomeField")}"); } } } }
这篇关于如何检测数据源的第一个或最后一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文