Find a row in a DataTable

I have a table in a DataSet and I want to search for a row in this table using a unique key.

My question is: is there any method that allows me to find this line without using loops?

This is the code I wrote using the forech loop:

foreach (var myRow in myClass.ds.Tables["Editeur"].AsEnumerable()) { if (newKeyWordAEditeurName == myRow[1] as String) id_Editeur_Editeur = (int)myRow[0]; } 
+4
source share
1 answer

Sure. You have a Select method from a DataTable. Extract the table from your DataSet and use Select to trick it.

 void Demo(DataSet ds) { DataTable dt = ds.Tables[0]; // refer to your table of interest within the DataSet dt.Select("Field = 1"); // replace with your criteria as appropriate } 
+13
source

Source: https://habr.com/ru/post/1436983/


All Articles