Could you point a way to obtain the a C# datatable row position after a successfull search in it?

Eduardo Fuerte
Eduardo Fuerte used Ask the Experts™
on
Hi Experts

Could you point a way to obtain the a C# datatable row position after a successfull search in it?

             // The value is founded in DataSet using the key  val1
             DataRow[] foundRow = dsProdutos.Tables[tabela].Select("sb_pub =" +val1);

            // How to obtain   the DataSet's line position  that detains the value founded (?)

Open in new window


Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010

Commented:
You can get the row index:

int index = dsProdutos.Tables[tabela].Rows.IndexOf(foundRow);

You'll want to verify foundRow is not null before you do this.
Retired
Distinguished Expert 2017
Commented:
Hi Eduardo;

This will do what you need.
// The value is founded in DataSet using the key  val1
DataRow[] foundRow = dsProdutos.Tables[tabela].Select("sb_pub =" +val1);

// Because it returns an array of DataRow's this will get index of all
foreach (DataRow row in foundRow)
{
    int rowIndex = dsProdutos.Tables[tabela].Rows.IndexOf(row);
    Console.WriteLine(rowIndex);
}

Open in new window

Eduardo FuerteDeveloper and Analyst

Author

Commented:
Thank you Fernando!
Fernando SotoRetired
Distinguished Expert 2017

Commented:
Not a problem Eduardo, glad to help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial