请高手指点:SQL查询数值型问题,用的是foxpro数据库,金额设置的类型为字符型.
PrivateSubCommand1_Click()DimSQLAsStringDimConnStrAsStringDimConnAsADODB.ConnectionDi...
Private Sub Command1_Click()
Dim SQL As String
Dim ConnStr As String
Dim Conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set Conn = New ADODB.Connection
'On Error GoTo MyErr:
ConnStr = "Provider=MSDASQL.1;Driver=Microsoft Visual Foxpro Driver;SourceDB=" & App.Path & "\data;Mode=ReadWrite;SourceType=DBF;;Persist Security Info=False"
Conn.Open ConnStr
rs.CursorLocation = adUseClient
SQL = "SELECT * FROM mingxi ORDER BY no"
If Val(Text2.Text) > 0 Then
If Text1.Text = "" Then
SQL = SQL & "and val(金额) <= & Val(Text2.Text) & "
Else
SQL = SQL & "and 金额 between & Val(Text1.Text) & and " & Val(Text2.Text) & ""
End If
End If
rs.Open Trim$(SQL), Conn, adOpenDynamic, adLockOptimistic
If rs.RecordCount > 0 Then
Text3.Text = rs.Fields("日期")
Text4.Text = Format(rs.Fields("金额"), "0.00")
Else
MsgBox "查无数据!", 64, "提示"
Exit Sub
End If
rs.Close
'exit sub
'MyErr:
'Set rs = Nothing
'Set Conn = Nothing '释放相关的系统资源
'MsgBox Err.Description, vbInformation, "系统提示" '显示出错信息
End Sub
错误提示:commands contains unrecognized phrase/keyword. 展开
Dim SQL As String
Dim ConnStr As String
Dim Conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set Conn = New ADODB.Connection
'On Error GoTo MyErr:
ConnStr = "Provider=MSDASQL.1;Driver=Microsoft Visual Foxpro Driver;SourceDB=" & App.Path & "\data;Mode=ReadWrite;SourceType=DBF;;Persist Security Info=False"
Conn.Open ConnStr
rs.CursorLocation = adUseClient
SQL = "SELECT * FROM mingxi ORDER BY no"
If Val(Text2.Text) > 0 Then
If Text1.Text = "" Then
SQL = SQL & "and val(金额) <= & Val(Text2.Text) & "
Else
SQL = SQL & "and 金额 between & Val(Text1.Text) & and " & Val(Text2.Text) & ""
End If
End If
rs.Open Trim$(SQL), Conn, adOpenDynamic, adLockOptimistic
If rs.RecordCount > 0 Then
Text3.Text = rs.Fields("日期")
Text4.Text = Format(rs.Fields("金额"), "0.00")
Else
MsgBox "查无数据!", 64, "提示"
Exit Sub
End If
rs.Close
'exit sub
'MyErr:
'Set rs = Nothing
'Set Conn = Nothing '释放相关的系统资源
'MsgBox Err.Description, vbInformation, "系统提示" '显示出错信息
End Sub
错误提示:commands contains unrecognized phrase/keyword. 展开
3个回答
2012-03-14
展开全部
按执行顺序,生成的SQL语句显然不正确
SQL = "SELECT * FROM mingxi ORDER BY no"
& "and val(金额) <= & Val(Text2.Text) &“
应该是Select * From mingXi Where ... and val(金额) <= & Val(Text2.Text) &“
SQL = "SELECT * FROM mingxi ORDER BY no"
& "and val(金额) <= & Val(Text2.Text) &“
应该是Select * From mingXi Where ... and val(金额) <= & Val(Text2.Text) &“
展开全部
Private Sub Command1_Click()
Dim SQL As String
Dim ConnStr As String
Dim Conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set Conn = New ADODB.Connection
'On Error GoTo MyErr:
ConnStr = "Provider=MSDASQL.1;Driver=Microsoft Visual Foxpro Driver;SourceDB=" & App.Path & "\data;Mode=ReadWrite;SourceType=DBF;;Persist Security Info=False"
Conn.Open ConnStr
rs.CursorLocation = adUseClient
SQL = "SELECT * FROM mingxi ORDER BY no"
If Val(Text2.Text) > 0 Then
If Text1.Text = "" Then
SQL = SQL & "and val(金额) <= " & Text2.Text
Else
SQL = SQL & "and 金额 between " & Text1.Text & " and " & Text2.Text
End If
End If
rs.Open Trim$(SQL), Conn, adOpenDynamic, adLockOptimistic
If rs.RecordCount > 0 Then
Text3.Text = rs.Fields("日期")
Text4.Text = Format(rs.Fields("金额"), "0.00")
Else
MsgBox "查无数据!", 64, "提示"
Exit Sub
End If
rs.Close
'exit sub
'MyErr:
'Set rs = Nothing
'Set Conn = Nothing '释放相关的系统资源
'MsgBox Err.Description, vbInformation, "系统提示" '显示出错信息
End Sub
Dim SQL As String
Dim ConnStr As String
Dim Conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set Conn = New ADODB.Connection
'On Error GoTo MyErr:
ConnStr = "Provider=MSDASQL.1;Driver=Microsoft Visual Foxpro Driver;SourceDB=" & App.Path & "\data;Mode=ReadWrite;SourceType=DBF;;Persist Security Info=False"
Conn.Open ConnStr
rs.CursorLocation = adUseClient
SQL = "SELECT * FROM mingxi ORDER BY no"
If Val(Text2.Text) > 0 Then
If Text1.Text = "" Then
SQL = SQL & "and val(金额) <= " & Text2.Text
Else
SQL = SQL & "and 金额 between " & Text1.Text & " and " & Text2.Text
End If
End If
rs.Open Trim$(SQL), Conn, adOpenDynamic, adLockOptimistic
If rs.RecordCount > 0 Then
Text3.Text = rs.Fields("日期")
Text4.Text = Format(rs.Fields("金额"), "0.00")
Else
MsgBox "查无数据!", 64, "提示"
Exit Sub
End If
rs.Close
'exit sub
'MyErr:
'Set rs = Nothing
'Set Conn = Nothing '释放相关的系统资源
'MsgBox Err.Description, vbInformation, "系统提示" '显示出错信息
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
做任务
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询