title: Visual Basic Database and registration form
body: <p>This is my first time doing VB. I have successfully created the login form, but I am having issues with the User Registration. The moment I  click register, it gives me error that Database connection Failed and cannot INSERT INTO Registration. Please help. 
  Thanks in advance </p>
  
  <pre><code>If rtxtpassword.Text = "" Or rtxtusername.Text = "" Or rtxtfname.Text = "" Or rtxtlname.Text = "" Then
              MessageBox.Show("Please complete the required fields..", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
          Else
          End If
  
          ' Connect to DB
          Dim conn As New System.Data.OleDb.OleDbConnection()
          conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\logan_000\documents\visual studio 2013\Projects\Point Of Sale Application\Point Of Sale Application\database.accdb"
  
          Try
              'Dim sql As String = "INSERT INTO Registration WHERE username='" &amp; rtxtusername.Text &amp; "' AND Password = '" &amp; rtxtpassword.Text &amp; rtxtfname.Text &amp; "' AND Fname = '" &amp; rtxtlname.Text &amp; "' AND Lname =  '"
              Dim sql As String = "INSERT INTO Registration (username, Password, Fname, Lname) VALUES (" &amp; rtxtusername.Text &amp; ", " &amp; rtxtpassword.Text &amp; ", " &amp; rtxtfname.Text &amp; ", " &amp; rtxtlname.Text &amp; ")"
              'Dim sql As String = "INSERT INTO Registration (username, Password, Fname, Lname) VALUES('" &amp; rtxtusername.Text &amp; "'," &amp; "'" &amp; rtxtpassword.Text &amp; "',"
              Dim sqlCom As New System.Data.OleDb.OleDbCommand(Sql)
  
              'Open Database Connection
              sqlCom.Connection = conn
              conn.Open()
              Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader()
  
              If sqlRead.Read() Then
                  Form1.Show()
                  'Me.Hide()
                  Me.Close()
              Else
                  ' If user enter wrong username and password combination
                  ' Throw an error message
                  MessageBox.Show("Registration Failed..", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  
                  'Clear all fields
                  rtxtusername.Text = ""
                  rtxtfname.Text = ""
                  rtxtlname.Text = ""
                  rtxtpassword.Text = ""
  
                  'Focus on Username field
                  rtxtusername.Focus()
              End If
              'Connection failure Dialog box
          Catch ex As Exception
              MessageBox.Show("Failed to connect to Database.. System Error Message:  " &amp; ex.Message, "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  
          End Try
  
      End Sub
  </code></pre>