[VB.NET]请大家帮忙看看,多条件查询的问题
2008-12-27 22:21
537 查看
<script type="text/javascript"><!--
google_ad_client = "pub-8333940862668978";
/* 728x90, 创建于 08-11-30 */
google_ad_slot = "4485230109";
google_ad_width = 728;
google_ad_height = 90;
//-->
</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 要用 & " " & 这样才行的。以字符串加进去。
__________________________________________________________________________
相关文章推荐
- [VB.NET]关于DataGridView的问题,会的请进来看看,帮忙解决!!
- N皇后问题的一个程序,请大家看看!帮忙修改
- 新手问题,大家帮忙看看..谁有意见散分给谁哦!
- 大家好这是我写的词典。很简单。我初学VB.NET请大家帮忙改进
- [VB.NET]大家看看,这段代码出错了,要怎么改,谢谢,,在线等,当天结贴!!!!!!
- 安装软件时出了个怪问题,我截了个图。大家帮忙看看
- [VB.NET]我是新手,想让高手帮忙解决个问题
- [VB.NET]引用和值类型的区别? 分不清了,麻烦大家看看我的代码.
- [VB.NET]最后一个问题,大家再帮兄弟一把!
- vb连接数据库中数据集的问题!!!!!(希望大家可以帮忙下,,谢了!!!)
- 代码问题,大家来帮忙看看啊
- achartengine之折线图---简单用法(续二)---(动态刷新)图形嵌套在页面(有问题请大家帮忙看看),已解决问题
- D-Day +6 of .NET 传说中的计算器问题.有BUG,解决不了,第一个程序怎么就调不好呢,高手帮忙看看
- [VB.NET]帮忙看看这些代码!!!
- 水晶报表问题汇总(水晶报表的使用与查询条件生成报表、注册码、打印问题、模式使用示例、C#.Net的WinForm中的使用、程序发布与部署)
- 关于图像绘制并输出的问题,大家帮忙看看
- [VB.NET]帮我看看这个问题!!!!!!!!
- [VB.NET]VB.net 读写ini的问题,希望好心人贡献下时间,帮忙解决下~~
- 初接触c语言,请大家帮忙看看问题出在哪了!
- vb.net中对于ORACLE的时间查询问题