Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         Dim conn As MySqlConnection
  2.         'connect to DB
  3.        conn = New MysqlConnection()
  4.         conn.ConnectionString = "server=yourwebsitehere.com; user id=your_username_here; password=your_password_here; database=yourdatabase_namehere"
  5.         'see if connection failed.
  6.        Try
  7.             conn.Open()
  8.         Catch myerror As MySqlException
  9.             MsgBox("Error connecting to database!")
  10.         End Try
  11.         'sql query
  12.        Dim myAdapter As New MySqlDataAdapter
  13.  
  14.         Dim sqlquery = "SELECT * FROM login WHERE username = '" + txtuser.Text + "'"
  15.         Dim myCommand As New MySqlCommand()
  16.         myCommand.Connection = conn
  17.         myCommand.CommandText = sqlquery
  18.         'start query
  19.        myAdapter.SelectCommand = myCommand
  20.         Dim myData As MySqlDataReader
  21.         myData = myCommand.ExecuteReader()
  22.         'see if user exists
  23.        If myData.HasRows = 0 Then
  24.  
  25.             conn.Close()
  26.             conn.Open()
  27.             Dim registerfinal As New MySqlDataAdapter
  28.  
  29.             sqlquery = "INSERT INTO login (Username, Password) VALUES ('" + txtuser.Text + "','" + txtpass.Text + "')"
  30.             myCommand.Connection = conn
  31.             myCommand.CommandText = sqlquery
  32.             'start query
  33.            registerfinal.SelectCommand = myCommand
  34.             myData = myCommand.ExecuteReader()
  35.             MsgBox("New user has been added to the database!")
  36.             Me.Hide()
  37.         Else
  38.             MsgBox("Login Accepted!")
  39.             Form1.Show()
  40.             Me.Hide()
  41.         End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement