请大家帮忙看看,多条件查询的问题
代码功能主要是在指定时间与识别号的综合查询,并将数据显示在dataGrid上。
Private Sub btnStat_Click(...)
Dim strFilter As String
If txbIDCard.Text.Trim.Length <> 0 Then
strFilter = "where 识别号 like ' "
strFilter += txbIDCard.Text.Trim + "% ' "
End If
Dim d1 As Date = Me.DateTimePicker1.Value
Dim d2 As Date = Me.DateTimePicker2.Value
Dim connectionString As String = "Persist Security Info=False;Integrated Security=SSPI;Database=shipping;Server=localhost "
Dim da As New SqlClient.SqlDataAdapter da.SelectCommand.CommandText = "SELECT 预定单号, 入库时间, 出库时间, 识别号 FROM 预定单 WHERE 入库时间> = ' " & d1 & " ' AND 出库时间 <= ' " & d2 & " ' " + strFilter '问题可能在这
Dim ds As New DataSet
da.Fill(ds)
dataGrid1.DataSource = ds.Tables(0)
end sub
问题可能是strFilter与入出库时间的联合查询上,请大家帮我改改,谢谢了。
[解决办法]
Dim da As New SqlClient.SqlDataAdapter( "SELECT 预定单号, 入库时间, 出库时间, 识别号 FROM 预定单 WHERE 入库时间> = ' " & d1 & " ' AND 离开时间 <= ' " & d2 & " ' " & strFilter, connectionString),试试