在vb里进行SQL查询时总是提示语句错误,能帮我看下这代码哪里有问题吗?
Dim strSQL As String
Dim strCon(7) As StringDim i As Integer
If Text1.Text <> "" Then
If Check1.Value = 1 Then
strCon(1) = "货物申请表.申请单号 like '%" & Text1.Text & "%'"
Else
strCon(1) = "货物申请表.申请单号='" & Text1.Text & "'"
End If
Else
strCon(1) = ""
End If
If Text2.Text <> "" Then
If Check1.Value = 1 Then
strCon(2) = "货物申请表.运单号 like '%" & Text2.Text & "%'"
Else
strCon(2) = "货物申请表.运单号='" & Text2.Text & "'"
End IfElse
strCon(2) = ""
End If
If Text3.Text <> "" Then
If Check1.Value = 1 Then
strCon(3) = "客户信息表.地址 like '%" & Text3.Text & "%'"
Else
strCon(3) = "客户信息表.地址 ='" & Text3.Text & "'"
End IfElse
strCon(3) = ""
End IfIf Text4.Text <> "" Then
If Check1.Value = 1 Then
strCon(4) = "货物申请表.收件人地址 like '%" & Text4.Text & "%'"
Else
strCon(4) = "货物申请表.收件人地址='" & Text4.Text & "'"
End If
Else
strCon(4) = ""
End IfIf Text5.Text <> "" Then
If Check1.Value = 1 Then
strCon(5) = "客户信息表.客户姓名 like '%" & Text5.Text & "%'"
Else
strCon(5) = "客户信息表.客户姓名='" & Text5.Text & "'"
End If
Else
strCon(5) = ""
End If
If Text6.Text <> "" Then
If Check1.Value = 1 Then
strCon(6) = "货物申请表.收件人姓名 like '%" & Text6.Text & "%'"
Else
strCon(6) = "货物申请表.收件人姓名='" & Text6.Text & "'"
End If
Else
strCon(6) = ""
End If
If Combo2.Text = "根据申请单号查询" Then
If Text7.Text <> "" Then
strCon(7) = "货物申请表.申请单号 ='" & Text7.Text & "'"
Else
strCon(7) = ""
End If
End IfIf Combo1.Text = "根据目的地查询" Then
If Text7.Text <> "" Then
strCon(7) = "货物申请表.收件人地址='" & Text7.Text & "'"
Else
strCon(7) = ""
End If
End IfIf Combo2.Text = "根据发件人查询" Then
If Text7.Text <> "" Then
strCon(7) = "客户信息表.客户姓名 ='" & Text7.Text & "'"
Else
strCon(7) = ""
End If
End IfIf Combo2.Text = "根据收件人查询" Then
If Text7.Text <> "" Then
strCon(7) = "货物申请表.收件人姓名 ='" & Text7.Text & "'"
Else
strCon(7) = ""
End If
End IfIf Combo2.Text = "根据快件状态查询" Then
If Text7.Text <> "" Then
strCon(7) = "在途跟踪信息表.运输状态 ='" & Text7.Text & "'"
Else
strCon(7) = ""
End If
End If
For i = 1 To 7
If strCon(i) <> "" Then
strSQL = strSQL + " and " + strCon(i)
End If
Next strSQL = "select 货物申请表.申请单号,货物申请表.运单号,客户信息表.地址," _
& " 货物申请表.收件人地址,客户信息表.客户姓名,货物申请表.收件人姓名,在途跟踪信息表.运输状态 from 货物申请表,在途跟踪信息表,客户信息表" _
& " where 货物申请表.申请单号 = 在途跟踪信息表.申请单号 and 货物申请表.运单号 = 在途跟踪信息表.运单号"
Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=物流管理;Initial Catalog=W-L"
Adodc1.CursorLocation = adUseClient
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strSQL
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
Dim strSQL As String
Dim strCon(7) As StringDim i As Integer
If Text1.Text <> "" Then
If Check1.Value = 1 Then
strCon(1) = "货物申请表.申请单号 like '%" & Text1.Text & "%'"
Else
strCon(1) = "货物申请表.申请单号='" & Text1.Text & "'"
End If
Else
strCon(1) = ""
End If
If Text2.Text <> "" Then
If Check1.Value = 1 Then
strCon(2) = "货物申请表.运单号 like '%" & Text2.Text & "%'"
Else
strCon(2) = "货物申请表.运单号='" & Text2.Text & "'"
End IfElse
strCon(2) = ""
End If
If Text3.Text <> "" Then
If Check1.Value = 1 Then
strCon(3) = "客户信息表.地址 like '%" & Text3.Text & "%'"
Else
strCon(3) = "客户信息表.地址 ='" & Text3.Text & "'"
End IfElse
strCon(3) = ""
End IfIf Text4.Text <> "" Then
If Check1.Value = 1 Then
strCon(4) = "货物申请表.收件人地址 like '%" & Text4.Text & "%'"
Else
strCon(4) = "货物申请表.收件人地址='" & Text4.Text & "'"
End If
Else
strCon(4) = ""
End IfIf Text5.Text <> "" Then
If Check1.Value = 1 Then
strCon(5) = "客户信息表.客户姓名 like '%" & Text5.Text & "%'"
Else
strCon(5) = "客户信息表.客户姓名='" & Text5.Text & "'"
End If
Else
strCon(5) = ""
End If
If Text6.Text <> "" Then
If Check1.Value = 1 Then
strCon(6) = "货物申请表.收件人姓名 like '%" & Text6.Text & "%'"
Else
strCon(6) = "货物申请表.收件人姓名='" & Text6.Text & "'"
End If
Else
strCon(6) = ""
End If
If Combo2.Text = "根据申请单号查询" Then
If Text7.Text <> "" Then
strCon(7) = "货物申请表.申请单号 ='" & Text7.Text & "'"
Else
strCon(7) = ""
End If
End IfIf Combo1.Text = "根据目的地查询" Then
If Text7.Text <> "" Then
strCon(7) = "货物申请表.收件人地址='" & Text7.Text & "'"
Else
strCon(7) = ""
End If
End IfIf Combo2.Text = "根据发件人查询" Then
If Text7.Text <> "" Then
strCon(7) = "客户信息表.客户姓名 ='" & Text7.Text & "'"
Else
strCon(7) = ""
End If
End IfIf Combo2.Text = "根据收件人查询" Then
If Text7.Text <> "" Then
strCon(7) = "货物申请表.收件人姓名 ='" & Text7.Text & "'"
Else
strCon(7) = ""
End If
End IfIf Combo2.Text = "根据快件状态查询" Then
If Text7.Text <> "" Then
strCon(7) = "在途跟踪信息表.运输状态 ='" & Text7.Text & "'"
Else
strCon(7) = ""
End If
End If
For i = 1 To 7
If strCon(i) <> "" Then
strSQL = strSQL + " and " + strCon(i)
End If
Next strSQL = "select 货物申请表.申请单号,货物申请表.运单号,客户信息表.地址," _
& " 货物申请表.收件人地址,客户信息表.客户姓名,货物申请表.收件人姓名,在途跟踪信息表.运输状态 from 货物申请表,在途跟踪信息表,客户信息表" _
& " where 货物申请表.申请单号 = 在途跟踪信息表.申请单号 and 货物申请表.运单号 = 在途跟踪信息表.运单号"
Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=物流管理;Initial Catalog=W-L"
Adodc1.CursorLocation = adUseClient
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strSQL
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
解决方案 »
- 关于VB中的MDI子窗体不能以模式窗体显示
- 关于sql server2000中数值保留两位小数的问题
- 关于调用ACCESS的版本问题~
- 关于删除记录的操作,大侠们一定在帮小弟。送大分:)
- SQL语句
- 用vb写Excel文件
- VB.NET中GantChart控件中的工作日与周末时间列的设置
- 表中有数个完全一样的记录,如何写sql语句只删除其中一条记录
- 用 Int((100000 * Rnd) + 1) 得到的随机数为什么总上不了90000?
- 运行时,会在executeNonQuery 出现未处理OleDbException,字符串错误,这应该怎么解决
- 求助。 EXCEL的VBA做一个个别点不一样的折线图,且可以放大缩小
- 各位 请教一个CAD加载用vb开发的exe问题
然后把语句贴到 SSMS 的查询窗口中执行,自然会指出错误行。
通过手工分行来确定错误位置。
Select 查询字段 from 表名 Where 查询条件语句 [排序语句或分组语句]
& " 货物申请表.收件人地址,客户信息表.客户姓名,货物申请表.收件人姓名,在途跟踪信息表.运输状态 from 货物申请表,在途跟踪信息表,客户信息表" _
& " where 货物申请表.申请单号 = 在途跟踪信息表.申请单号 and 货物申请表.运单号 = 在途跟踪信息表.运单号 and 货物申请表.客户ID = 客户信息表.客户ID"没有给出客户信息表的关联条件。