![]() |
|
[.NET] Vb.net - access database - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Vb.net - access database (/showthread.php?tid=5864478) |
Vb.net - access database - Uija - Jul 21, 2018 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 RE: Vb.net - access database - aneeshkollam5 - Jul 22, 2018 Using dbCommand As OleDbCommand = New OleDbCommand("Select * FROM Arbeiter WHERE Forname ='" & strUsername & "'", dbConnection) Dim dr As OleDbDataReader = dbCommand.ExecuteReader() If dr.HasRows Then boolUsernameExists = True MsgBox("Username already exists") Else End If RE: Vb.net - access database - Uija - Jul 22, 2018 (Jul 22, 2018 02:28 AM)aneeshkollam5 Wrote: Using dbCommand As OleDbCommand = New OleDbCommand("Select * FROM Arbeiter WHERE Forname ='" & strUsername & "'", dbConnection) Thank you ! This works 🤗 |