Reputation: 15
So I've done a lot of searching for this one and can't figure it out. I have a csv file that i'm writing off to a DataTable and populating a combo box from that same datatable. The Idea is to search a user selected value in the data table and return the ID of that selection from the same data table. The problem I'm having is that the selections all have spaces since they are capacity environments. Is there a way to take the string and search the datatable column "Description" and return the column "ID"? here is the code:
internal static void envRequest(string e)
{
DataRow[] foundRows;
foundRows = variables.capEnvTable.Select(e);
//variables.envID = foundRows[0].ToString();
Thread.Sleep(200);
Console.WriteLine(foundRows.ToString());
}
}
The DataTable is formated as "ID" - "Name" - "Description"
The value of e is the user selected value such as "Buckeye Hosting Zone 2 Aries"
Right now I'm getting a System.Data.SyntaxErrorException: 'Syntax error: Missing operand after 'Hosting' operator.' on the foundRows = variables.capEnvTable.Select(e);
Upvotes: 0
Views: 513
Reputation: 4033
Ok lets say the first column (index 0) is the value you want to search and the 2nd column (index 1) is the value you want.
DataRow dataRow;
dataRow =
myDataGridView.Rows.Cast<DataRow>()
.FirstOrDefault( row => row[0] == "ValueYouWantToSearch" );
var value = dataRow[1];
Upvotes: 1