如何从数据集中选择记录? [英] How to ger Selected Records From Dataset ?
本文介绍了如何从数据集中选择记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我从数据库中重新获取数据。数据是
ID速度
1 40
2 30
3 0
4 0
5 0
6 0
7 20
这里我的问题是如何将Speed = 0记录作为另一个数据集中的一条记录。看看bleow输出
ID速度
1 40
2 30
3到6 0
7 20
任何人都可以指导我如何将此输出转换为另一个数据集。
记录
Nanda Kishore.CH
Hi to all,
I retrived data from database. The data is
ID Speed
1 40
2 30
3 0
4 0
5 0
6 0
7 20
Here my problem is how to get the Speed = 0 records as one record in another dataset. see bleow output
ID Speed
1 40
2 30
3 to 6 0
7 20
Could anyone guide me how to get this output to another dataset.
Records
Nanda Kishore.CH
推荐答案
试试这个解决方案
使用Linq On过滤器在数据表中使用IN和Not In子句 [ ^ ]
Try this solution
Filter Using Linq On datatable with "IN" and "Not In" Clause[^]
您可以使用datatable.Select( )方法,您将获得datarow集合,然后您可以将这些行集合插入到新数据集中。
You can use datatable.Select() method, you would have got the datarow collection then you can insert these row collection into your new dataset.
Dim drFilter() As DataRow
drFilter = DataSet.Tables("TableName").Select("Speed = 0")
而不是使用数据集使用数据表并尝试以下代码
instead of using dataset use data table and try the below code
SqlDataAdapter da = new SqlDataAdapter("select id,speed from tablename", objCon);
int[] array = new int[5];
int i=0;
DataTable DataTabledt1 = new DataTable("speed");
da.Fill(DataTabledt1);
DataColumn dc = DataTabledt1.Columns["speed"];
DataColumn dc1 = DataTabledt1.Columns["id"];
foreach (DataRow row in DataTabledt1.Rows)
{
if(Convert.ToInt32(row[dc].ToString())==0)
{
array[i]=Convert.ToInt32(row[dc1].ToString());
}
}
if(array.count>0)
{
Response.write(array[0]+"to"+array[array.count-1]+"0" )
}
这篇关于如何从数据集中选择记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文