title: Register Form Issues VB.Net
body: <p>I am having an issue when I am setting up this Register form.
  My current code is this:</p>
  
  <pre><code>Public Class Form2
  Dim con As New OleDb.OleDbConnection
  
  Dim dbProvider As String
  Dim dbSource As String
  Dim MyDocumentsFolder As String
  Dim TheDatabase As String
  Dim FullDatabasePath As String
  Dim ds As New DataSet
  Dim da As OleDb.OleDbDataAdapter
  Dim sql As String
  Dim DBTest1 As String
  Dim DBTestP1 As String
  Dim cmd As New OleDbCommand(sql, con)
  Dim connStr As String
  
  Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Dim connection As New OleDb.OleDbConnection(connStr)
      dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
  
      TheDatabase = "\Robocopy_Test.accdb"
      MyDocumentsFolder = "C:\Users\Dan\Desktop\WindowsApplication2"
      FullDatabasePath = MyDocumentsFolder &amp; TheDatabase
  
      dbSource = "Data Source = C:\Users\Dan\Desktop\WindowsApplication2\Robocopy_Testaccdb1.accdb"
  
      con.ConnectionString = dbProvider &amp; dbSource
  
      con.Open()
      sql = "SELECT * FROM Robocopy"
      da = New OleDb.OleDbDataAdapter(sql, con)
      'da.Fill(ds, "Robocopy")
      MessageBox.Show("Databse is Open")
      DBTest1 = DBTest.Text
      DBTestP1 = DBTestP.Text
      'DBTest.Text = ds.Tables("Robocopy").Rows(0).Item(1)
      'DBTestP.Text = ds.Tables("Robocopy").Rows(0).Item(2
      sql = "INSERT INTO Robocopy(username,password) VALUES('" &amp; DBTest1 &amp; "','" &amp; DBTestP1 &amp; "')"
      cmd.Connection = connection
      connection.Open()
      cmd.CommandText = sql
      da.InsertCommand = cmd
      da.InsertCommand.ExecuteNonQuery()
      connection.Close()
      'With cmd.Parameters
      '.AddWithValue("usernamer", DBTest.Text)
      '.AddWithValue("password", DBTestP.Text)
      '.AddWithValue("email", txtsub.text)
      '.AddWithValue("contactnum", txtau.text)
      'End With
      'cmd.ExecuteNonQuery()
  End Sub
  
  Public Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
      con.Close()
      MessageBox.Show("Database Is now Closed")
  End Sub
  </code></pre>
  
  <p>End Class</p>
  
  <p>I am having the issue at connection.open(). The error that I am having is 
  The ConnectionString property has not been initialized.
  I have been trying for the past hour to find different ways to write to the database but to no prevail and I cannot figure this out.</p>
  
  <p>[In response to Steve
  My code after editing and still the same error</p>
  
  <pre><code>Imports System.Data.OleDb
  
  Public Class Form2
  Dim connection As New OleDb.OleDbConnection
  
  Dim dbProvider As String
  Dim dbSource As String
  Dim MyDocumentsFolder As String
  Dim TheDatabase As String
  Dim FullDatabasePath As String
  Dim ds As New DataSet
  Dim da As OleDb.OleDbDataAdapter
  Dim sql As String
  Dim DBTest1 As String
  Dim DBTestP1 As String
  Dim cmd As New OleDbCommand(sql, connection)
  Dim connStr As String
  
  Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Dim connection As New OleDb.OleDbConnection(connStr)
      dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
  
      TheDatabase = "\Robocopy_Test.accdb"
      MyDocumentsFolder = "C:\Users\Dan\Desktop\WindowsApplication2"
      FullDatabasePath = MyDocumentsFolder &amp; TheDatabase
  
      dbSource = "Data Source = C:\Users\Dan\Desktop\WindowsApplication2\Robocopy_Testaccdb1.accdb"
  
      Me.connection.ConnectionString = dbProvider &amp; dbSource
  
      Me.connection.Open()
      sql = "SELECT * FROM Robocopy"
      da = New OleDb.OleDbDataAdapter(sql, connection)
      'da.Fill(ds, "Robocopy")
      MessageBox.Show("Databse is Open")
      DBTest1 = DBTest.Text
      DBTestP1 = DBTestP.Text
      'DBTest.Text = ds.Tables("Robocopy").Rows(0).Item(1)
      'DBTestP.Text = ds.Tables("Robocopy").Rows(0).Item(2
      sql = "INSERT INTO Robocopy(username,password) VALUES('" &amp; DBTest1 &amp; "','" &amp; DBTestP1 &amp; "')"
      cmd.Connection = connection
      connection.Open()
      cmd.CommandText = sql
      da.InsertCommand = cmd
      da.InsertCommand.ExecuteNonQuery()
      connection.Close()
      'With cmd.Parameters
      '.AddWithValue("usernamer", DBTest.Text)
      '.AddWithValue("password", DBTestP.Text)
      '.AddWithValue("email", txtsub.text)
      '.AddWithValue("contactnum", txtau.text)
      'End With
      'cmd.ExecuteNonQuery()
  End Sub
  
  Public Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
      connection.Close()
      MessageBox.Show("Database Is now Closed")
  End Sub
  End Class
  </code></pre>