title: How to view data between two dates in vb.net using the datetimepicker
body: <pre><code>Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
      Dim cn As New SqlConnection
      Dim ds As New DataSet
      Dim dt As New DataTable
      Dim dfrom As DateTime
      Dim dto As DateTime
      Dim da As New SqlDataAdapter
  
      dfrom = dtpicker1.Text
      dto = dtpicker2.Text
  
      cn.ConnectionString = "Data Source=JMI-PC\SQLEXPRESS;Initial Catalog=student_system;User Id=ian;Password=rockstar"
      cn.Open()
      Dim str As String
      Format(dtpicker1.Text, "yyyy-MM-dd")
      Format(dtpicker2.Text, "yyyy-MM-dd")
      str = "select Exam_Date from class1  where Exam_Date= '" &amp; dtpicker1.Text &amp; "' and Exam_Date='" &amp; dtpicker2.Text &amp; "'"
  
      da = New SqlDataAdapter(str, cn)
      da.Fill(dt)
      DataGridView1.DataSource = dt
      DataGridView1.DataSource = dt
  
  
  End Sub
  </code></pre>
  
  <p>i am trying to view data between two dates using the datetimepicker and when i try to run this code i get an error aying "  Conversion failed when converting date and/or time from character string." if anyone can show me how its done, i would really appreciate it</p>