Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

Hello shashikant86,

C#
//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 ;
        }
    }
 
Share this answer
 
C#
//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
}
 
Share this answer
 
I have written below code to resolved issue

VB
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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900