Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Project - Messenger
#8
Well heres the code to read from a database :
Code:
conn = New MySqlConnection
        conn.ConnectionString = "server=SERVER.COM;Port=3306; user id=USERID; password=PASSWORD; database=DATABASE"
        Try
            conn.Open()
            Dim sqlquery = "SELECT * From Users WHERE username='" & textbox1.text & "'"
            Dim command As New MySqlCommand
            Dim adapter As New MySqlDataAdapter
            Dim data As MySqlDataReader
command.Connection = conn
            command.CommandText = sqlquery
            adapter.SelectCommand = command
            data = command.ExecuteReader

Thats to open the connection. To check if a username exists, use this (for logging in)

Code:
If data.HasRows = 0 Then
                MsgBox("Error! - Wrong User ID or Password", MsgBoxStyle.Critical, "Error!")
                conn.Close()
            Else

                data.Close()
                conn.Close()
                command.Connection = conn
                command.CommandText = "SELECT * From Users WHERE username='" & login_username.Text & "'AND PASSWORD='" & login_password.Text & "';"
                conn.Open()
                data = command.ExecuteReader

Then to create a new account...
Code:
sqlquery = "INSERT INTO Users (Username, Password) VALUES('" & txtbox_username.Text & "','" & txtbox_password.Text &  "' )"
                command.Connection = conn
                command.CommandText = sqlquery
                registerfinal.SelectCommand = command
                data = command.ExecuteReader
                MsgBox("Account has been created! - Please try logging in with these credentials to test the account!", MsgBoxStyle.Information, "Account Created!")

Hope this helps!
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Project - Messenger - by xolara - 11-25-2010, 02:30 PM
Re: Project - Messenger - by xolara - 11-29-2010, 02:01 PM
Re: Project - Messenger - by xolara - 11-29-2010, 09:03 PM
Re: Project - Messenger - by xolara - 12-02-2010, 07:06 PM
Re: Project - Messenger - by xolara - 12-18-2010, 12:21 PM
Re: Project - Messenger - by brandonio21_phpbb3_import2 - 12-18-2010, 12:53 PM
Re: Project - Messenger - by Josh - 12-01-2013, 09:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Anyone intereted In Helping With This Project? arrelin1 1 11,135 06-19-2013, 11:56 PM
Last Post: brandonio21
  New project? LearningVB2010 8 27,976 09-09-2011, 05:51 AM
Last Post: LearningVB2010

Forum Jump:


Users browsing this thread: 1 Guest(s)