RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Vb.net with Mysql

localhost

Wanderer
Vb.net with Mysql

I've been trying to make my own login/registration system in vb.net, with not too much luck. I got most of my information from www.vbmysql.com, but still haven't been able to complete the login form. I'm trying to connect to the database, users, and the table user. Right now, I'm just trying to retrive the username data and compare it. I'm hopelessly lost now, and on the verge of giving up. Please help me!

Below is a small piece of my code.

Code:
        If user.Text = "" Then
            MsgBox("Enter a Username!")
        Else
            If pass.Text = "" Then
                MsgBox("Enter a Password!")
            Else
                conn = New MySqlConnection()
                conn.ConnectionString = "server=localhost; user id=root; password=; database=users"

            End If
            Try
                conn.Open()
                sSQL = "SELECT * FROM user where user= '" & user.Text & "'"
                conn.Close()
                If sSQL = user.Text Then
                    MsgBox("Success!")
                    work = 1
                End If
            Catch myerror As MySqlException
*** Rest of the code ***
 

Vitas

Sorceror
same problem...

I can't connect to the server that runs uo kr server to mysql... its pain in ass... so just keep trying....
 

Ray

Sorceror
localhost;537181 said:
Code:
        If user.Text = "" Then
            MsgBox("Enter a Username!")
        Else
            If pass.Text = "" Then
                MsgBox("Enter a Password!")
            Else
                conn = New MySqlConnection()
                conn.ConnectionString = "server=localhost; user id=root; password=; database=users"

            End If
            Try
                conn.Open()
                sSQL = "SELECT * FROM user where user= '" & user.Text & "'"
                conn.Close()
                If sSQL = user.Text Then
                    MsgBox("Success!")
                    work = 1
                End If
            Catch myerror As MySqlException
*** Rest of the code ***

This fails, because you haven't executed any query right now.
The assignment of a query to the string sSQL doesn't execute the query, so If sSQL = user.Text Then compares to the SELECT[...] string, which failes unless the user writes exatly this sentence into the textbox.
Please take a look on the MySQLCommand class on how to execute a MySQLReader Query.

something like this: (not tested, written right of my mind)
Code:
        If user.Text = "" Then
            MsgBox("Enter a Username!")
        Else If pass.Text = "" Then
                MsgBox("Enter a Password!")
        Else
                conn = New MySqlConnection()
                conn.ConnectionString = "server=localhost; user id=root; password=; database=users"

            Try
                conn.Open()
                sSQL = "SELECT * FROM user where user LIKE '" & user.Text & "' AND password = '" & pass.Text & "'"
                Dim command As MySQLCommand = new MySQLCommand( conn, sSQL )
                Dim reader As MySQLReader = command.ExecuteReader()
                While reader.Read()
                    If reader("user").ToString() = user.Text Then
                        MessageBox.Show("Success!") ' do NOT use the Microsoft.VisualBasic namespace, except in legacy code!
                        work = 1
                    End If
                Loop
                conn.Close()
            Catch myerror As MySqlException
       End If
*** Rest of the code ***

Please be aware that this code is very vulnerable to SQL-Injection-attacks, unless you start using parameters (MySQLParameter) correctly. Highly recommended not to use it in production code. But should be quite enough to get you some steps further :)
 
Top