Jul 21, 2018 08:42 AM
(This post was last modified: Jul 21, 2018 08:44 AM by Uija.)
Hello everyone ,
at the beginning of my program you have to register. But what if the username already exists?I already wrote something , but It does nothing 😶 (when I click on the button it says nothing..)
Can someone say me what did I wrong ?
My code :
Imports System.Data.OleDb
Public Class Form1
Dim boolUsernameExists As Boolean = False
Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click
Dim strUsername As String = FlatTextBox1.Text
Try
If String.IsNullOrEmpty(strUsername) Then
Return
End If
Using dbConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\bin\Debug\Arbeiter.mdb")
dbConnection.Open()
Using dbCommand As OleDbCommand = New OleDbCommand("Select Count(*) FROM Arbeiter WHERE Forname LIKE?", dbConnection) ' "Arbeiter" is the name of the table and "Forname" is the username
dbCommand.Parameters.AddWithValue("@p1", strUsername)
Dim result As Integer = DirectCast(dbCommand.ExecuteScalar(), Integer)
If result > 0 Then
boolUsernameExists = True
MsgBox("Username already exists")
Else
End If
End Using
dbConnection.Close()
End Using
If boolUsernameExists Then
MsgBox("Username already exists")
Return
End If
Catch ex As Exception
End Try
End Sub
at the beginning of my program you have to register. But what if the username already exists?I already wrote something , but It does nothing 😶 (when I click on the button it says nothing..)
Can someone say me what did I wrong ?
My code :
Imports System.Data.OleDb
Public Class Form1
Dim boolUsernameExists As Boolean = False
Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click
Dim strUsername As String = FlatTextBox1.Text
Try
If String.IsNullOrEmpty(strUsername) Then
Return
End If
Using dbConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\bin\Debug\Arbeiter.mdb")
dbConnection.Open()
Using dbCommand As OleDbCommand = New OleDbCommand("Select Count(*) FROM Arbeiter WHERE Forname LIKE?", dbConnection) ' "Arbeiter" is the name of the table and "Forname" is the username
dbCommand.Parameters.AddWithValue("@p1", strUsername)
Dim result As Integer = DirectCast(dbCommand.ExecuteScalar(), Integer)
If result > 0 Then
boolUsernameExists = True
MsgBox("Username already exists")
Else
End If
End Using
dbConnection.Close()
End Using
If boolUsernameExists Then
MsgBox("Username already exists")
Return
End If
Catch ex As Exception
End Try
End Sub

