title: How to insert selected records into the another table in VB 2008
body: <p>I have created a Form1 in Visual Basic 2008 and on that Form1 I have placed two TextBoxes, Two DateTimePicker and one Button. Further in M. S. Access I have created a database with Two tables tableA and tableB. Here I want to retrieve selected records only from tableA and Insert into tableB.</p>
  
  <pre><code>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)   Handles Button1.Click
  
      Connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\TAMBE-DATABASE\SANJAY_PUNE.mdb")
      Connection.Open()
      Command = New OleDbCommand(" insert into tableB select * FROM tableA ", Connection)
      Command.ExecuteNonQuery()
      Command.Dispose()
      Connection.Close()
      MsgBox("Records Added Successfully")
  End Sub
  </code></pre>
  
  <p>When I try to execute it all the rows have been added into the table B. I don't want to add all the records. I want to add only selected rows. When I change in selected stated statement as </p>
  
  <pre><code>Command = New OleDbCommand(" insert into tableB select * FROM tableA where DATE_OF_SELL BETWEEN '" &amp; TextBox1.Text "' AND '" &amp; TextBox2.Text "'", Connection)
  </code></pre>
  
  <p>Here in text boxes I have selected a date From and To because I want to retrieve selected date from <code>DATE_OF_SELL</code> field. When I try to execute it there is an error.</p>