title: Failed to emit module BC36970 Visual Basic AND VB.NET
body: <p>I have method to fill DataGridView from SQL server database between tow dates my date column date in database is Date in this format "dd/MM/yyyy h:mm:ss tt", and this is the query:</p>
  
  <pre><code>Const sql As String = "SELECT * FROM money_sent WHERE date BETWEEN '2016-08-01 04:01:59.000' AND '2016-09-10 04:02:05.000'"
  </code></pre>
  
  <p>until now everything perfect , when I tried to use datetimepicker I get 2 errors:</p>
  
  <p>"Constant expression is required"(for picker 1) </p>
  
  <p>"Constant expression is required"(for picker 2)</p>
  
  <pre><code>Const sql As String = "SELECT * FROM money_sent WHERE date BETWEEN '" &amp; DateTimePicker1.Value &amp; "' AND '" &amp; DateTimePicker1.Value &amp; "'" 
  </code></pre>
  
  <p>After this I tried to do this:</p>
  
  <pre><code>    Dim date1 As DateTime = DateTimePicker1.Value
      Dim date2 As DateTime = DateTimePicker2.Value
      Const sql As String = "SELECT * FROM money_sent WHERE date BETWEEN '" &amp; date1 &amp; "' AND '" &amp; date2 &amp; "'"
  </code></pre>
  
  <p>Now I getting this error:</p>
  
  <p>Failed to emit module'WindowsApplication.exe' (BC36970 Visual Basic AND  VB.NET Failed to emit module.)</p>
  
  <p>What I can do in this situation please help</p>
  
  <p>This is the method code :</p>
  
  <pre><code>If Conn.State = ConnectionState.Open Then
          Conn.Close()
      End If
      Conn.Open()
      Dim date1 As DateTime = DateTimePicker1.Value
      Dim date2 As DateTime = DateTimePicker2.Value
      Const sql As String = "SELECT * FROM money_sent WHERE date BETWEEN '" &amp; date1 &amp; "' AND '" &amp; date2 &amp; "'"
  
      Dim adt As New SqlDataAdapter(sql, Conn)
      Dim dt As New DataTable
      adt.Fill(dt)
      Dim i As Integer
      For i = 0 To dt.Rows.Count - 1
          MetroGrid2.Rows.Add()
          MetroGrid2.Rows(i).Cells(1).Value = dt.Rows(i).ItemArray(1)
          Dim cell As DataGridViewComboBoxCell = DirectCast(MetroGrid2.Rows(i).Cells(2), DataGridViewComboBoxCell)
          cell.Value = dt.Rows(i).ItemArray(2)
          MetroGrid2.Rows(i).Cells(3).Value = dt.Rows(i).ItemArray(3)
          MetroGrid2.Rows(i).Cells(4).Value = dt.Rows(i).ItemArray(4)
          'DataGridView1.Rows(i).Cells(4).Value = "DELETE"
          MetroGrid2.Rows(i).Cells(5).Value = dt.Rows(i).ItemArray(5)
          MetroGrid2.Rows(i).Cells(6).Value = dt.Rows(i).ItemArray(6)
          MetroGrid2.Rows(i).Cells(7).Value = dt.Rows(i).ItemArray(7)
          MetroGrid2.Rows(i).Cells(8).Value = dt.Rows(i).ItemArray(8)
          MetroGrid2.Rows(i).Cells(9).Value = dt.Rows(i).ItemArray(9)
          MetroGrid2.Rows(i).Cells(10).Value = dt.Rows(i).ItemArray(10)
          MetroGrid2.Rows(i).Cells(12).Value = dt.Rows(i).ItemArray(12)
          MetroGrid2.Rows(i).Cells(13).Value = dt.Rows(i).ItemArray(0)
      Next
      Conn.Close() 
  </code></pre>