The skin I wrote only takes the Text without the Value in order to look good. Now use this method to solve the inconvenient way of only taking the Value from the Text. You only need a method to query all the data in this table. Of course, you can also only return these two. List
code
/// <summary>
/// Get the index based on the column name
/// </summary>
/// <param name="fiId">Column name</param>
/// <returns>Column index</returns>
private string GetFunctionNameByName(string Name)
{
var result = this.objWSM.GetFunctionInfo().AsEnumerable().Where(f1 => f1["fiName"].ToString().Trim() == Name.ToString().Trim()).FirstOrDefault() ;
return result["fiId"].ToString();
}
GetFunctionInfo is a method that queries all information in the table
/// <summary>
/// Get the column name based on the column index
/// </summary>
/// <param name="fiId">Column index</param>
/// <returns>Column name</returns>
private string GetFunctionNameById(int fiId)
{
var result = this._fiTable.AsEnumerable().Where(fi => Convert.ToInt32(fi["fiId"]) == fiId).FirstOrDefault();
return result["fiName"].ToString();
}
The two methods are corresponding. I feel that it is much more convenient to query this way. It can be completed directly at the front desk. When connecting to the database, you only need to query all methods at once.
Let me explain this step.
this.objWSM.GetFunctionInfo().AsEnumerable().Where(f1 => f1["fiName"].ToString().Trim() == Name.ToString().Trim()).FirstOrDefault();
this.objWSM.GetFunctionInfo() is a method to query all
AsEnumerable().Where() returns a generic row, which can be queried using LinQ expressions
f1 => f1["fiName"].ToString().Trim() == Name.ToString().Trim())Linq expression
F1 is the name of a newly generated row
f1["fiName"]. Of course it is the column name in this row, => followed by the condition and preceded by the set
f1["fiName"].ToString().Trim() == Name.ToString().Trim() means that if there are two equal values in this line, take them out
FirstOrDefault(); means taking the first row
At this point, the problem is almost solved. As long as there is a method to query these two columns, write these two methods in the front desk, and it will be OK every time. There is no need to write two special methods to access the database, which feels very convenient.