Guest User

Untitled

a guest
Jan 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.49 KB | None | 0 0
  1. Imports Microsoft.VisualBasic.FileIO.FileSystem
  2. Imports Microsoft.VisualBasic.FileIO.SpecialDirectories
  3. Imports MySql.Data.MySqlClient
  4. Imports MySql.Data.Types
  5. Imports MySql.Web.Common
  6. Public Class Register
  7.  
  8.     Private Sub Register_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9.  
  10.     End Sub
  11.  
  12.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  13.         TextBox1.Text = Nothing
  14.         TextBox2.Text = Nothing
  15.         Login.Show()
  16.         Me.Close()
  17.     End Sub
  18.     Public conn As MySqlConnection
  19.  
  20.     Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  21.         If TextBox2.Text = TextBox3.Text = True Then
  22.  
  23.             conn = New MySqlConnection("server=server.net;Port=3306; user id=sqluser; password=sqlpass; database=Users")
  24.             Dim username As Boolean = True
  25.             conn.Open()
  26.             Dim sqlquery As String = "SELECT * FROM Users WHERE Username = '" & TextBox1.Text & "';"
  27.             Dim data As MySqlDataReader
  28.             Dim adapter As New MySqlDataAdapter
  29.             Dim command As New MySqlCommand
  30.             command.CommandText = sqlquery
  31.             command.Connection = conn
  32.             adapter.SelectCommand = command
  33.             data = command.ExecuteReader
  34.             While data.Read()
  35.                 If data.HasRows() = True Then
  36.                     MsgBox("Username Already in use!")
  37.                     username = False
  38.                     data.Close()
  39.                 Else
  40.                     data.Close()
  41.                     username = True
  42.                 End If
  43.             End While
  44.             data.Close()
  45.             If username = True Then
  46.                 Dim sqlquery2 As String = "INSERT INTO Users (Username, Password)VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
  47.                 Dim data2 As MySqlDataReader
  48.                 Dim adapter2 As New MySqlDataAdapter
  49.                 Dim command2 As New MySqlCommand
  50.                 command2.CommandText = sqlquery2
  51.                 command2.Connection = conn
  52.                 adapter2.SelectCommand = command2
  53.                 data2 = command2.ExecuteReader
  54.                 MsgBox("You've Registered!")
  55.                 Login.Show()
  56.  
  57.             End If
  58.         End If
  59.         If TextBox2.Text = TextBox3.Text = False Then
  60.             MsgBox("Password fields not matching")
  61.         End If
  62.         Me.Close()
  63.     End Sub
  64. End Class
Add Comment
Please, Sign In to add comment