Firstly, I am not sure this is the best way of doing this.
I have imported data from an excel to create a DataTable. I then have data input that I need to parse out and create a (small L) list of items.
I then want to check whether any of those items appear in the DataTable and if they do, produce an output from a different column.
I created a List<string> for the parsed items, and have been trying to figure out how to loop through the DataTable and loop through the List looking for each item.
I kinda got this far, but I know this is just wrong on so many levels....
I think it is the IF statement where I can't get my head to wrap around the concept. For instance, I know that row.ToString() just gives me a System.Data response rather than the contents of that row. I know that finalResult[ i ].ToString() doesn't really seem to give me anything.
I just run out of steam, it is 2am and my brain is fried and thought perhaps writing it out here would help - it actually sometimes does, just writing out the question can sometimes help in understanding the problem....but not this time, it didn't help.
So any pointers gratefully received.
I have imported data from an excel to create a DataTable. I then have data input that I need to parse out and create a (small L) list of items.
I then want to check whether any of those items appear in the DataTable and if they do, produce an output from a different column.
I created a List<string> for the parsed items, and have been trying to figure out how to loop through the DataTable and loop through the List looking for each item.
I kinda got this far, but I know this is just wrong on so many levels....
C#:
List<string> finalResult = new List<string>();
//code to fill the list
foreach (DataRow row in table.Rows)
{
int i;
for (i = 0; i < finalResult.Count; i++)
{
if (row.ToString() == finalResult[i].ToString())
{
itemsFoundTB.Text += row.ToString();
}
}
I think it is the IF statement where I can't get my head to wrap around the concept. For instance, I know that row.ToString() just gives me a System.Data response rather than the contents of that row. I know that finalResult[ i ].ToString() doesn't really seem to give me anything.
I just run out of steam, it is 2am and my brain is fried and thought perhaps writing it out here would help - it actually sometimes does, just writing out the question can sometimes help in understanding the problem....but not this time, it didn't help.
So any pointers gratefully received.