Fare un criterio di stringa da cercare, in questo modo:
string searchExpression = "ID = 5"
quindi utilizzare il metodo del DataTable
.Select()
oggetto, come questo:
DataRow[] foundRows = YourDataTable.Select(searchExpression);
Ora è possibile scorrere i risultati, come questo:
int numberOfCalls;
bool result;
foreach(DataRow dr in foundRows)
{
// Get value of Calls here
result = Int32.TryParse(dr["Calls"], out numberOfCalls);
// Optionally, you can check the result of the attempted try parse here
// and do something if you wish
if(result)
{
// Try parse to 32-bit integer worked
}
else
{
// Try parse to 32-bit integer failed
}
}
fonte
2013-12-17 15:43:48
Non potresti farlo come parte dell'istruzione select? "SELEZIONA ID, chiama FROM MyTable WHERE ID = @ id_search". Quindi basta fornire il parametro "@id_search" alla chiamata del database. Questo sarà più veloce di LINQ, specialmente assumendo che l'ID sia una chiave primaria o indicizzata. –
Non un database, dataset/datatable im fear. – RSM