在数据集中需要帮助 [英] need help in dataset
本文介绍了在数据集中需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助以满足以下要求。
我有一个数据集。数据集有很多列并包含值。
在我的本地变量中,我存储了一个字符串值。
现在我的问题是我怎么能检查变量值是否存在特定列数据集中的所有行。
例如
i有数据集两个颜色EMPName和EMPId。
我在变量中有一个字符串TEST。
现在我想检查EMPName列中的TEST
Hi,
I want a help in following requirment.
I have one dataset. Dataset has many columns and contain values.
In my local variable i have stored one string value.
Now my question is how can i check variable value is there exist in particular column all rows in dataset.
e.g.
i have dataset with two coloumns EMPName and EMPId.
I have one string "TEST" in varible.
now i want to check "TEST" is there in EMPName column
推荐答案
你好shashikant86,
Hello shashikant86,
//Dataset Itself can not contains Rows and coloumns .
//Dataset will contain Datatable in it .
//and in that datatable (dt) we will check the number of rows in datatable
Bool IsExist = false ;
for (int i = 0;i < ds.Tables[0].rows.count;i++)
{
if(ds.Tables[0].rows[i].contains("TEST"))
{
IsExist = true ;
}
}
//Sample code
int TotalCount = 0;
int MatchedCount = 0;
DataRow[] drMatched;
drMatched = dataSet1.Tables["Employee"].Select("EmpName Like 'TEST%'");
TotalCount = dataSet1.Tables["Employee"].Rows.Count;
MatchedCount = drMatched.Length;
if(TotalCount != MatchedCount)
{
//if code
}
else
{
//else code
}
>
我写下以下代码解决了问题
I have written below code to resolved issue
If ds.Tables.Count > 0 Then
If ds.Tables(0).Rows.Count > 0 Then
For Each row As DataRow In ds.Tables(0).Rows
If row("EMPName") = "TEST" Then
Return
Else
End If
Next
End If
Else
End If
这篇关于在数据集中需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文