Compare Values in Table RRS feed

  • Question

  • I have a table called "Users" in my lightswitch application (local db).  On that table there is a field called username.

    As a user enters a username and the field loses focus, I want to check the database to see if any other users have that username and if so, throw an error.  I'm using the following code, but it gives me an error because it cannot convert a User to a String.  And if I try to make the username field a string to begin with it throws another error - even though in my table it IS a string.

    here - result is just the string value of the username property of the current user (the one I'm adding/creating)

    For Each Username As String In Me.DataWorkspace.ApplicationData.Users
                            If Username = result Then
                                isunique = isunique + 1
                            End If

    Friday, March 11, 2016 5:54 PM

All replies

  • Something like this might help.  ~Untested Air Code~

    'Use this in server validation code for the UserName property of the Users table.
    Dim DuplicateUserName = Me.DataWorkspace.ApplicationData.Users.Where(Function (a) (a.UserName = Me.UserName) AndAlso (a.Id <> Me.Id)).FirstOrDefault()
    If DuplicateUserName IsNot Nothing Then
       result = AddPropertyError("This user name already exists)
    End If

    Friday, March 11, 2016 10:05 PM