title: creating tables in Access using VB.NET
body: <p>I'm having trouble creating Access tables from VB.NET.</p>
  
  <p>This is the code I have come up with but I keep getting errors:</p>
  
  <pre><code>   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Try
          'connection string
          Dim dbpath As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
          dbpath = New Uri(dbpath).LocalPath
          Dim my_connection As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\GhostDrive\Desktop\database.mdb"
          Dim userTables As DataTable = Nothing
          Dim connection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection()
          Dim source As String
  
          'query string
          Dim my_query As String = "CREATE TABLE " &amp; TextBox2.Text &amp; " ( " &amp; _
              "ID Counter, " &amp; _
              "Year datetime," &amp; _
              "Title varchar(40)," &amp; _
              "image1 Long," &amp; _
              "Image2 Long," &amp; _
              "Image3 Long," &amp; _
              "Image4 Long," &amp; _
              "Serial varchar(20)," &amp; _
              "Purchaseprice Currency," &amp; _
              "Evalprice Currency, " &amp; _
              "Datepurchase DateTime, " &amp; _
              "Dateeval DateTime, " &amp; _
              "Sign varchar(40), " &amp; _
              "Grading varchar(20)," &amp; _
              "Eval YesNo, " &amp; _
              "Star YesNo, " &amp; _
              "Folder YesNo, " &amp; _
              "Forsale YesNo, " &amp; _
              "Error YesNo, " &amp; _
              "Barcode(varchar(20)," &amp; _
              "Comm YesNo )"
  
          'create a connection
          Dim my_dbConnection As New OleDbConnection(my_connection)
  
          'create a command
          Dim my_Command As New OleDbCommand(my_query, my_dbConnection)
  
          'connection open
          my_dbConnection.Open()
  
          'command execute
          my_Command.ExecuteNonQuery()
  
          'close connection
          my_dbConnection.Close()
          ListBox1.Items.Clear()
          source = TextBox1.Text
          connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + source
          Dim restrictions() As String = New String(3) {}
          restrictions(3) = "Table"
          connection.Open()
          ' Get list of user tables
          userTables = connection.GetSchema("Tables", restrictions)
          connection.Close()
          ' Add list of table names to listBox
          Dim i As Integer
          For i = 0 To userTables.Rows.Count - 1 Step i + 1
              ListBox1.Items.Add(userTables.Rows(i)(2).ToString())
          Next
  
      Catch ex As Exception
          MsgBox(ex.Message)
      End Try
  
  
  End Sub
  </code></pre>