1

bound sourceデータ行を使用して、VB 2010の(SQLテーブル)内の2つの日付の間を検索しようとしています。'between'はデータ行関数でサポートされていないため、とを使用<>ました。
したがって、このコードを実行すると、実際のエントリ数が8の場合、出力は900以上のエントリになります。何も変更せずにボタンをもう一度押すと、正しいエントリ数が表示されます。

Private Sub cmdSearch_Click(sender As System.Object, e As System.EventArgs) _ 
                                                    Handles cmdSearch.Click

    Dim Expression As String
    Dim OrderStr As String = "Area"
    Dim DateStr As String
    Dim StartDate As String
    Dim EndDate As String
    Dim Shift As String = ""
    Dim Area As String = ""
    Dim Product As String

    If (DtpStartDate.Value = Nothing Or DtpEndDate.Value = Nothing) Then
        MsgBox("Please input a start and end date.")
        Exit Sub
    End If

    If (radShiftAllSearch.Checked <> True _ 
            And radShiftOneSearch.Checked <> True 
            And radShiftTwoSearch.Checked <> True _ 
            And radShiftThreeSearch.Checked <> True) Then
        MsgBox("Please select a shift to search for.")
        Exit Sub
    End If

    Select Case True
        Case radShiftOneSearch.Checked
            Shift = " AND [Shift] = '1'"
        Case radShiftTwoSearch.Checked
            Shift = " AND [Shift] = '2'"
        Case radShiftThreeSearch.Checked
            Shift = " AND [Shift] = '3'"
        Case radShiftAllSearch.Checked
            Shift = " AND ([Shift] = '1' OR [Shift] = '2' OR [Shift] = '3')"
    End Select


    **StartDate = DtpStartDate.Value.Subtract(oneday)
    EndDate = DtpEndDate.Value.Add(oneday)
    'StartDate = Format(DtpStartDate.Value.Subtract(oneday), "M/dd/yyyy")
    'EndDate = Format(DtpEndDate.Value.Add(oneday), "M/dd/yyyy")
    DateStr = "[Dates] > '" & StartDate & "' AND [Dates] < '" & EndDate & "'"**

    If (txtProductSearch.Text = "") Then
        Product = ""
    Else
        Product = "AND [Product] LIKE '" & txtProductSearch.Text & "'"
    End If

    For h As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
        Dim XDRV As DataRowView = CType(CheckedListBox1.CheckedItems(h), DataRowView)
        Dim XDR As DataRow = XDRV.Row
        Dim XDisplayMember As String = XDR(CheckedListBox1.DisplayMember).ToString()
        If (Area = "") Then
            Area = Area & " AND ([Area] LIKE '" & XDisplayMember & "'"
        Else
            Area = Area & " OR [Area] LIKE '" & XDisplayMember & "'"
        End If
    Next

    If (Area <> "") Then
        Area = Area & ")"
    End If

    Expression = DateStr & Product & Shift & Area
    TextBox4.Text = Expression

    Dim SearchRows() As DataRow = _ 
    ProductionDataSet.Tables("Production_Daily").Select(Expression, OrderStr)
    'foundcount = SearchRows.Count - 1

    DataGridView1.DataSource = SearchRows
    DataGridView1.Show()


End Sub

ありがとう

4

0 に答える 0