无法发出模块BC36970 Visual Basic和VB.NET

时间:2016-09-21 01:35:50

标签: vb.net

我有方法在两个日期之间从SQL服务器数据库填充DataGridView我的数据库中的日期列日期是这种格式的日期" dd / MM / yyyy h:mm:ss tt",这是查询:

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'"

直到现在一切都很完美,当我尝试使用datetimepicker时,我得到了2个错误:

"需要常量表达式"(对于选择器1)

"需要常量表达式"(对于选择器2)

Const sql As String = "SELECT * FROM money_sent WHERE date BETWEEN '" & DateTimePicker1.Value & "' AND '" & DateTimePicker1.Value & "'" 

在此之后我尝试这样做:

    Dim date1 As DateTime = DateTimePicker1.Value
    Dim date2 As DateTime = DateTimePicker2.Value
    Const sql As String = "SELECT * FROM money_sent WHERE date BETWEEN '" & date1 & "' AND '" & date2 & "'"

现在我收到了这个错误:

无法发出模块' WindowsApplication.exe' (BC36970 Visual Basic和VB.NET无法发出模块。)

在这种情况下我能做些什么请帮助

这是方法代码:

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 '" & date1 & "' AND '" & date2 & "'"

    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() 

0 个答案:

没有答案