Linq to select a value from a cloumn based on value in a variable

dtData.Select(“[GAPROVISION]=12”)(0).Item(“PROVISIONID”).ToString this code is working

But when using varible to pass value then it is not working
dtData.Select(“[GAPROVISION]=provisonID”)(0).Item(“PROVISIONID”).ToString(this code is not working)

1 Like

If you are looking to mimic your exact top one, you need to alter it so it passes the string value of “12” at runtime (assuming provisionID is an integer & it is 12 for this example).

dtData.Select(“[GAPROVISION]=” + provisonID.ToString + “”)(0).Item(“PROVISIONID”).ToString

You may need to play with the quotes a bit, but the idea is to have a string ending at …GAPROVISION]=, then throw in the variable converted to string, then start the string again at "(0).Item…

EDIT: Here is an old thread asking a similar question: How to use variables in