tags:

views:

25

answers:

1

Hi,

How can i check if a dataset contains a specific value? It's crazy that no one has done this before. Couldn't find it on the net!!!

+2  A: 

You mean go through the entire dataset tables, columns and rows?

Here is something that could help you:

Dim valueToSearch as String = "some text"
For Each dTable As DataTable In ds.Tables
    For Each dRow As DataRow In dTable.Rows
        For index As Integer = 0 To dTable.Columns.Count - 1
            Convert.ToString(dRow(index)).Contains(valueToSearch)
        Next
    Next
Next
Darkxes
@Darkxes, that's exactly what I mean, although its a very very smal dataset. Shouldn't take that long. So how is this done? I still havent found anything on the net!!!
Yustme
check out my edition ...
Darkxes
Datasets hold tables, each table holds rows, each row holds items. In Darkxes example you would check drow(index) for the specific value you are looking for. If you know the exact column it will be in you can skip the inner most loop, and just check dRow("columnname") for your value.
asawyer
i know the table name, but where do i check for the string im looking for? dRow("colmnname").Contains(string) would be my first guess, but 'contains' doenst excist in that context.
Yustme
You can index directly against a datarow to retreive the stored value. See the msdn article for the DataRow object. http://msdn.microsoft.com/en-us/library/system.data.datarow.aspx
asawyer