A
AbanoubZak
Guest
Hello,
I made an app using login to act and i need to add feature where the client add more users
DB is SQL server
so as a first procedure I make if statement to check if the new user is already in database by
If LoginUsersTableAdapter.Fill_searchname(Username.Text) > 0 Then
MessageBox.Show("Username already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
I'm using query which i made as next " Select * from Loginusers where Username=@Usnername"
so the problem is my application ignore the if statement totally as if it's not exist and give me this error
it`s normal to give me the error because i set the primary key in the table at Username so they can't be duplicated
I just don`t know why it ignore my IF statment and by the way if the new Username wasn't exist in DB it will be added with no problem.
the following is my full code
Private Sub Addnew_click(sender As Object, e As EventArgs) Handles Addnew.Click
Try
If Username.Text.Length <= 0 Then
MessageBox.Show("Please enter Username!")
Exit Sub
ElseIf Password.Text.Length <= 0 Then
MessageBox.Show("Please enter Password!")
Exit Sub
ElseIf Usertype.Text.Length <= 0 Then
MessageBox.Show("Please enter Password!")
Exit Sub
End If
If LoginUsersTableAdapter.Fill_searchname(Username.Text) > 0 Then
MessageBox.Show("Username already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
LoginUsersTableAdapter.Insert(Username.Text, Password.Text, Usertype.Text)
MessageBox.Show("User has been added", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Thanks in advance.
Continue reading...
I made an app using login to act and i need to add feature where the client add more users
DB is SQL server
so as a first procedure I make if statement to check if the new user is already in database by
If LoginUsersTableAdapter.Fill_searchname(Username.Text) > 0 Then
MessageBox.Show("Username already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
I'm using query which i made as next " Select * from Loginusers where Username=@Usnername"
so the problem is my application ignore the if statement totally as if it's not exist and give me this error
it`s normal to give me the error because i set the primary key in the table at Username so they can't be duplicated
I just don`t know why it ignore my IF statment and by the way if the new Username wasn't exist in DB it will be added with no problem.
the following is my full code
Private Sub Addnew_click(sender As Object, e As EventArgs) Handles Addnew.Click
Try
If Username.Text.Length <= 0 Then
MessageBox.Show("Please enter Username!")
Exit Sub
ElseIf Password.Text.Length <= 0 Then
MessageBox.Show("Please enter Password!")
Exit Sub
ElseIf Usertype.Text.Length <= 0 Then
MessageBox.Show("Please enter Password!")
Exit Sub
End If
If LoginUsersTableAdapter.Fill_searchname(Username.Text) > 0 Then
MessageBox.Show("Username already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
LoginUsersTableAdapter.Insert(Username.Text, Password.Text, Usertype.Text)
MessageBox.Show("User has been added", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Thanks in advance.
Continue reading...