This question is locked. New answers and comments are not allowed.
Hello,
I am trying to use a LINQ query to get the value of a particular field from a database view (VwUserInformation). I pass in the name of the field that I want (fieldName) into the function and use it in the query as the parameter for FieldValue. See the code below.
On the first call to the function I set fieldName to "UserID", I get the data that is in the UserID field. On the second call, fieldName equals "UserFullName", but I still get the data from the UserID field. Even if I put in a bad value for fieldName (a field name that doesn't exist in the table), I still get the UserID and no error. Is there a way to fix this so I get the value of the field I specify and not just the value of the first field that was sent to this function?
Mark
I am trying to use a LINQ query to get the value of a particular field from a database view (VwUserInformation). I pass in the name of the field that I want (fieldName) into the function and use it in the query as the parameter for FieldValue. See the code below.
On the first call to the function I set fieldName to "UserID", I get the data that is in the UserID field. On the second call, fieldName equals "UserFullName", but I still get the data from the UserID field. Even if I put in a bad value for fieldName (a field name that doesn't exist in the table), I still get the UserID and no error. Is there a way to fix this so I get the value of the field I specify and not just the value of the first field that was sent to this function?
Mark
Public Function GetUserData(ByVal fieldName As String, ByVal userID As String, Optional ByVal defaultValue As String = "") As String Implements IMedVizerDbCom.GetUserData Dim dbData As String Dim tempUserData As Object Dim id As New Guid(userID) dbData = Nothing Dim x As IQueryable(Of Object) = From users In dbContext.VwUserInformation Where (users.UserID = id) Select users.FieldValue(Of Object)(fieldName) tempUserData = x.First If (Object.ReferenceEquals(tempUserData.GetType(), New Boolean().GetType)) Then If (DirectCast(tempUserData, Boolean) = True) Then dbData = "1" Else dbData = "0" End If Else dbData = tempUserData.ToString End If If (dbData Is Nothing) Then dbData = defaultValue End If Return dbData End Function