0

I'm currently working on a bit of homework for school, and am almost done, however I've got an issue with trying to run a query to match some user data. Every time I run the debugging process, it comes up time and again with the issue of 'Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.' I'm not sure what I'm doing wrong, or how to get past it. Is there something up with my query, or with my code?

Public Class Login_Processing
Dim adapter As New RRBCDataSetTableAdapters.LoginTableAdapter

Dim blnPass As Boolean
Public Function Login(ByVal Username As String, ByVal Password As String) As Boolean
    Try
        If adapter.GetUserNames(Username).ToString = "VViscioni" Or _
            adapter.GetUserNames(Username).ToString = "Whiter" Then
            If adapter.GetPassword(Username).ToString = Password Then
                frmMain.tsiAdmin.Enabled = True
                frmMain.tsiEAdmin.Enabled = True
                frmMain.tsiEPlayer.Enabled = True
                MessageBox.Show("Welcome back!")
                blnPass = True
            Else
                MsgBox("Is this a new user?", MsgBoxStyle.YesNo)
                If vbYes Then
                    AddAUser.ShowDialog()
                Else
                    MessageBox.Show("Please re-input your password.")
                    blnPass = False
                End If
            End If
        ElseIf adapter.GetUserNames(Username).ToString = Username Then
            If adapter.GetPassword(Username).ToString = Password Then
                frmMain.tsiEPlayer.Enabled = True
                MessageBox.Show("Welcome to the Roadrunners Baseball Club!")
                blnPass = True
            Else
                MessageBox.Show("Please re-input your password.")
                blnPass = False
            End If
        End If
    Catch ex As Exception
        MessageBox.Show("Please re-input your username/password.")
        blnPass = False
    End Try
    Return blnPass
End Function
End Class

Here's the SQL queries I'm trying to use for the adapters:

GetUserName Query:

SELECT Login FROM Login
WHERE (Login = @Login)

GetPassword Query:

SELECT Password FROM Login
WHERE (Login = @Login)

The parameters in the function relate to a Username and Password entry the user has to input.

NFSRacer
  • 19
  • 1
  • 8
  • Are you really working in VBA? That aside, there's clearly a bunch of more relevant code you've not included in your question. – Tim Williams Dec 06 '13 at 23:58
  • Ah, I keep getting the two mixed up. It's VB.NET, I want to say. All I know is that I'm doing it in Visual Studio 2012. As per the other code, that's just about it, aside from maybe an adapter definition, a Boolean definition, a pair of query's for my database, and a means to launch the function from another form, which is just one line long. What all else do I need to show? – NFSRacer Dec 07 '13 at 00:16
  • Okay, I was wrong, it is VB.NET. I know it might seem like I don't know what I'm doing, but I'm learning, so give me a bit of a break. – NFSRacer Dec 07 '13 at 00:21
  • What's the code behind `adapter` ? – Tim Williams Dec 07 '13 at 00:29
  • This may be relevant: http://stackoverflow.com/questions/8448271/failed-to-enable-constraints-one-or-more-rows-contain-values-violating-non-null – Tim Williams Dec 07 '13 at 00:31
  • Well, since you asked, go ahead and check the code again. That is, literally, all the relevant code for the task I'm trying to do, and the error I'm getting, aside from the SQL queries, which I'll add up in a moment. – NFSRacer Dec 07 '13 at 00:38
  • So there's no class in your project named `RRBCDataSetTableAdapters.LoginTableAdapter` ? – Tim Williams Dec 07 '13 at 00:41
  • I just found it easier to work it within the class. Is it really needed for the adapter to be outside the class? – NFSRacer Dec 07 '13 at 00:42
  • What I'm trying to say is that your posted code is a long way off from being *all* the code being run here... If you look at the link I posted, I think you may get some ideas about how to fix your problem. Without access to the rest of your project it's very difficult to make concrete suggestions. – Tim Williams Dec 07 '13 at 00:54
  • Well, I don't know what all else code you'd need that relevant to the issue being flagged by Visual Studio. The program flags the first If statement in the function with the error mentioned. I don't know what else could be linked to it. – NFSRacer Dec 07 '13 at 00:59
  • Check out the link @TimWilliams provided and this one to help you track down the issue: http://stackoverflow.com/questions/7026566/failed-to-enable-constraints-one-or-more-rows-contain-values-violating-non-null – NoAlias Dec 07 '13 at 01:50
  • That first link doesn't exactly help me, and the second is for C#, right? Neither of those work. Just tell me what code you need to understand my problem. – NFSRacer Dec 07 '13 at 02:05
  • Okay, just had an odd development. Stepping through the code, I've noticed that, strangely, the program picks out the COLUMN name, rather than the entry that gets queried up! Is there a fix to this? – NFSRacer Dec 07 '13 at 05:58

0 Answers0