Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27184

VB.net SQL Help login system

$
0
0
for some reason this doesnt work.. idk get it the register works but when u click log in it doesn't say any errors but it doesn't work either it doesn't even show MsgBox("Login") or MsgBox( "failed")


Code:

Imports MySql.Data.MySqlClient

Public Class Main
    Private mysql_host = "localhost"
    Private mysql_user = "root"
    Private mysql_pass = "890086212"
    Private mysql_db = "bloodynations"

    Public SQLConnect As String = "Server=" + mysql_host + ";" + "User Id=" + mysql_user + ";" + "Password=" + mysql_pass + ";" + "Database=" + mysql_db
    Private SQLConnection As New MySqlConnection
    Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SQLConnection.ConnectionString = SQLConnect
        Try
            If SQLConnection.State = ConnectionState.Closed Then
                SQLConnection.Open()
                MsgBox("Connection Sucessful")
            Else
                SQLConnection.Open()
                MsgBox("Connection Failed")
            End If
        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try
    End Sub

    Private Sub OK_Click(sender As Object, e As EventArgs) Handles OK.Click
        Try
            Dim sqlquery As String = "SELECT * FROM `Account` WHERE `Username` = ('" & Username.Text & "') AND `Password` = ('" & Password.Text & "')"
            Dim data As MySqlDataReader
            Dim adapter As New MySqlDataAdapter
            Dim command As New MySqlCommand
            command.CommandText = sqlquery
            command.Connection = SQLConnection
            adapter.SelectCommand = command
            data = command.ExecuteReader
            While data.Read()
                If data.HasRows() = True Then
                    If data(2).ToString = Username.Text And Password.Text Then
                        MsgBox("Login")
                    Else
                        MsgBox("Failed Login")
                    End If
                Else
                    MsgBox("Failed Login")
                    Me.Close()
                End If
            End While

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Cancel_Click(sender As Object, e As EventArgs) Handles Cancel.Click
        Dim SQlStatement As String = "INSERT INTO Account (Username, Password,Score) VALUES ('" & Username.Text & "','" & Password.Text & "',0 )"
        Dim cmd As New MySqlCommand
        With cmd
            .CommandText = SQlStatement
            .CommandType = CommandType.Text
            .Connection = SQLConnection
            .ExecuteNonQuery()
        End With
        MsgBox("Sucessfully Registered")
        Me.Hide()
    End Sub
End Class


Viewing all articles
Browse latest Browse all 27184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>