[VB.NET]请大家帮忙看看,多条件查询的问题

VB.NET源码-156个实用实例哦…… <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
请大家帮忙看看,多条件查询的问题
代码功能主要是在指定时间与识别号的综合查询,并将数据显示在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与入出库时间的联合查询上,请大家帮我改改,谢谢了。
__________________________________________________________________________
检查下da.SelectCommand.CommandText的输出信息

你会发现da.SelectCommand.CommandText 多了一个where~~~

改:
If txbIDCard.Text.Trim.Length <> 0 Then
strFilter = "and 识别号 like '' "
strFilter += txbIDCard.Text.Trim + "% '' "
End If
__________________________________________________________________________
一看就知道两个条件连不起来..你的加号在里面没有用.用AND连接.
__________________________________________________________________________
楼上的hainannewcon,请问怎么解决?
__________________________________________________________________________
没有全部看完。
strFilter = "where 识别号 like '' "
strFilter += txbIDCard.Text.Trim + "% '' "

将这里的where 去掉,在 += 后加个 and.
写的好乱。
__________________________________________________________________________
+ strFilter ----〉and strFilter
看这样能连上不.
__________________________________________________________________________
先谢谢各位的指教

“在 += 后加个 and.”会出现语法错误
+ strFilter ----〉and strFilter 问题还在
__________________________________________________________________________
Private Sub btnStat_Click(...)
Dim strFilter As String
If txbIDCard.Text.Trim.Length <> 0 Then
strFilter = " 识别号 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 & " '' " and strFilter ''
Dim ds As New DataSet
da.Fill(ds)
dataGrid1.DataSource = ds.Tables(0)
end sub


=============
这样可能可以,我没有调试过.你可以调试下,注意看看SELECT前面的引号有没有对应结束的引号.
__________________________________________________________________________
Dim da As New SqlClient.SqlDataAdapter( "SELECT 预定单号, 入库时间, 出库时间, 识别号 FROM 预定单 WHERE 入库时间> = '' " & d1 & " '' AND 离开时间 <= '' " & d2 & " '' " & strFilter, connectionString),试试
__________________________________________________________________________
and 要用 & " " & 这样才行的。以字符串加进去。
__________________________________________________________________________
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值