Protected Sub BT_查詢2_Click(sender As Object, e As EventArgs) Handles BT_查詢2.Click
Dim 起始日期 As String = TB2_起始日期.Text
Dim 結束日期 As String = TB2_結束日期.Text
Dim 裝箱編號 As String = TB2_裝箱編號.Text
Dim 產品編號 As String = TB2_產品編號.Text
Dim Cnt As Integer = CInt(Trim(Cnt_TB2.Text))
Dim Slt As String = ""
If Cnt = 0 Then '未輸入任何資料時,搜尋全部
Slt = ""
Else '有輸入資料時
Dim i As Integer = 0
If 起始日期 <> "" Then
i += 1
Slt = " WHERE [OutDate] >= '" & 起始日期 & "'"
End If
If 結束日期 <> "" Then
i += 1
If i = 1 Then
Slt += " WHERE"
Else
Slt += " AND"
End If
Slt += " [OutDate] <= '" & 結束日期 & "'"
End If
If 裝箱編號 <> "" Then
i += 1
If i = 1 Then
Slt += " WHERE"
Else
Slt += " AND"
End If
Slt += " [StorageNo] = '" & 裝箱編號 & " '"
End If
If 產品編號 <> "" Then
i += 1
If i = 1 Then
Slt += " WHERE"
Else
Slt += " AND"
End If
Slt += " [PPTNo] = '" & 產品編號 & "'"
End If
End If
SQL = "Select * FROM [Pro_A]" + Slt + " Order By PPTNo"
SQL_Select.Text = SQL
'將Select結果顯示到GridView
SqlDataSource1.SelectCommand = SQL
GridView.DataBind()
SqlDataSource1.Dispose()
End Sub
原文" [StorageNo] = '" & 裝箱編號 & " '"
原本需提供完整編號才能查詢
想改成僅提供該編號前2~3碼就可以查詢到相關訊息
Slt += " [StorageNo] like '%" & 裝箱編號 & "%'"