EvilZone

Programming and Scripting => .NET Framework => : hanorotu January 18, 2013, 12:57:41 AM

: VB 2012 Login Validation question [OPEN]
: hanorotu January 18, 2013, 12:57:41 AM
My problem is with the checking of the username and password against a mysql database, I'm not sure how I would go about doing it. I have searched google but haven't been able to find anything I can understand. Don't give me the answer, just help me out. I am trying to learn.
:
Imports System.Data.SqlClient
Imports System.Data.Sql

Public Class LoginForm1


    Private Sub OK_Click() Handles OK.Click
        Dim Selection() As String = {"SELECT * FROM `users` WHERE `username` = `" + TxtUsername.Text.ToString() + "` AND `password` = `" + TxtPassword.Text.ToString() + "`;"}
        MySql("server=;Port=; user id: password: database=", Selection)
       
            If ???.HasRows = 0 Then
            MsgBox("Bad Login")
        Else
            Form1.Show()
            Application.ExitThread()
        End If
    End Sub

    Private Sub Cancel_Click() Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub LoginForm1_Load() Handles MyBase.Load

    End Sub

    Private Sub LogoPictureBox_Click() Handles LogoPictureBox.Click

    End Sub

    Private Sub MySql(ByVal ConnectionString As String, ByVal query_array() As String)
        Try
            Using MySqlConnection As New SqlConnection(ConnectionString.ToString())
                For i = 0 To query_array.Length Step 1
                    Dim MySqlCommand As New SqlCommand(query_array(i), MySqlConnection)
                    MySqlCommand.Connection.Open()
                    MySqlCommand.ExecuteNonQuery()

                Next
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

End Class
: Re: VB 2012 Login Validation question [OPEN]
: Kulverstukas January 18, 2013, 08:55:25 AM
Your SQL looks wrong. Comparison in SQL is the same as anywhere - you need to use ==. Now you just have 1 =.

Also doesn't VB have some string formation methods? combining with +'s looks ugly.