I am trying to assign a variable to a select using LINQ.
What my function does that evaluates a data set to obtain the SourceID according to the caption that has been passed inside the select.
What I am trying to do is from an application in Windows Forms. When the user enters the value of this caption in a textBox, this value can be replaced by the existing value of the LINQ.
Here is my function:
private string GetMappingTable()
{
string SourceID = "";
var ds = GetMappingTable();
foreach (DataTable dst in ds.Tables)
{
foreach (DataRow dr in dst.Rows)
{
var DataSourceId = ds.Tables["Table"]
.Select("Caption = 'testUSers'")
.Select(r => r["SourceID"])
.Where(s => s != DBNull.Value)
.Select(s => s.ToString())
.FirstOrDefault();
SourceID = DataSourceId;
}
}
return SourceID;
}
I wish that where .Select("Caption = 'testUSers'")
the user says from the texBox another caption can be entered and that can be replaced.
Example:
In the select it says 'testUsers', if the user decides to put Users. This should be put in the caption value where it says testUsers.
How could I do that?
Thanks in advance.
The first thing you can do is have the GetMappingTable() function receive a parameter, which would be the user input.
Then to replace the value inside the function you can do it as follows
or this other way
What you have to do is instead of writing the testUSers by default, handle it as a String variable within the GetMappingTable() method, and in the .Select method you concatenate that variable as follows: .Select("Caption = ' " + text + "'")
This way you will get a change in the "text" every time you modify the content of your variable. Cheers