MrFancyPants
Nieuwe gebruiker
- Lid geworden
- 16 jan 2011
- Berichten
- 1
Ik ben bezig met een project en heb mn programma al zover gekregen te verbinden met mysql. Nu wil ik dat de user kan inloggen via 2 textboxen, die dan de username en het wachtwoord controleren met de data in de mysql database. En daar loop is vast...
hier is de code van de login sequentie.
ToolStripStatusLabel1.Text = "Verbinden..."
Dim connection As MySqlConnection
connection = New MySqlConnection()
Dim cmd As New SqlCommand
connection.ConnectionString = "Server=localhost; Uid=root; Pwd=; Database=verzuim;"
Try
connection.Open()
ToolStripStatusLabel1.Text = "Verbonden!"
Catch mysql_error As MySqlException
ToolStripStatusLabel1.Text = ("Fout tijdens verbinden met database: " & mysql_error.Message)
GoTo end1
End Try
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As MySqlDataReader
Dim SQL As String
Dim Email As String = TextBox1.Text.Replace("'", "\'")
Dim Password As String = TextBox2.Text.Replace("'", "\'")
SQL = "SELECT * FROM `users` WHERE `email` = '" + Email + "' AND `password` = '" + Password + "'"
myCommand.Connection = connection
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
Try
ToolStripStatusLabel1.Text = "Acountinformatie ontvangen..."
myData = myCommand.ExecuteReader()
myData.Read()
If myData.HasRows = 0 Then
ToolStripStatusLabel1.Text = ("Onbekende gebruikersnaam en wachtwoord!.")
Form2.Show()
connection.Close()
myData.Close()
Else
MsgBox("Welcome " + myData.GetString("fname") + "!.")
myData.Close()
End If
Catch ex As MySqlException
MsgBox(ex.Message)
End Try
end1:
hier is de code van de login sequentie.
ToolStripStatusLabel1.Text = "Verbinden..."
Dim connection As MySqlConnection
connection = New MySqlConnection()
Dim cmd As New SqlCommand
connection.ConnectionString = "Server=localhost; Uid=root; Pwd=; Database=verzuim;"
Try
connection.Open()
ToolStripStatusLabel1.Text = "Verbonden!"
Catch mysql_error As MySqlException
ToolStripStatusLabel1.Text = ("Fout tijdens verbinden met database: " & mysql_error.Message)
GoTo end1
End Try
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As MySqlDataReader
Dim SQL As String
Dim Email As String = TextBox1.Text.Replace("'", "\'")
Dim Password As String = TextBox2.Text.Replace("'", "\'")
SQL = "SELECT * FROM `users` WHERE `email` = '" + Email + "' AND `password` = '" + Password + "'"
myCommand.Connection = connection
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
Try
ToolStripStatusLabel1.Text = "Acountinformatie ontvangen..."
myData = myCommand.ExecuteReader()
myData.Read()
If myData.HasRows = 0 Then
ToolStripStatusLabel1.Text = ("Onbekende gebruikersnaam en wachtwoord!.")
Form2.Show()
connection.Close()
myData.Close()
Else
MsgBox("Welcome " + myData.GetString("fname") + "!.")
myData.Close()
End If
Catch ex As MySqlException
MsgBox(ex.Message)
End Try
end1: