两条语句的区别?If Combo1.Text = "进价" Or Combo1.Text = "数量" Or Combo1.Text = "金额" ThenSet rs = conn.Execute("select * from purchase where " & Combo1.Text & "=" & Combo2.Text)ElseSet rs = conn.Execute("select * from purchase where "
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 14:52:17
两条语句的区别?If Combo1.Text = "进价" Or Combo1.Text = "数量" Or Combo1.Text = "金额" ThenSet rs = conn.Execute("select * from purchase where " & Combo1.Text & "=" & Combo2.Text)ElseSet rs = conn.Execute("select * from purchase where "
两条语句的区别?
If Combo1.Text = "进价" Or Combo1.Text = "数量" Or Combo1.Text = "金额" Then
Set rs = conn.Execute("select * from purchase where " & Combo1.Text & "=" & Combo2.Text)
Else
Set rs = conn.Execute("select * from purchase where " & Combo1.Text & "='" & Combo2.Text & "'")
End If
请问("select * from purchase where " & Combo1.Text & "=" & Combo2.Text) 与
("select * from purchase where " & Combo1.Text & "='" & Combo2.Text & "'") 的区别在哪里?
两条语句的区别?If Combo1.Text = "进价" Or Combo1.Text = "数量" Or Combo1.Text = "金额" ThenSet rs = conn.Execute("select * from purchase where " & Combo1.Text & "=" & Combo2.Text)ElseSet rs = conn.Execute("select * from purchase where "
区别就在于参数的数据类型
("select * from purchase where " & Combo1.Text & "=" & Combo2.Text)
此时的Combo2.Text 是数字型
这句等同于
("select * from purchase where " & Combo1.Text & "=" & Combo2.Text&")
Set rs = conn.Execute("select * from purchase where " & Combo1.Text & "='" & Combo2.Text & "'")
此时的Combo2.Text 是文本型
原代码中的判断是为了区别数据类型
这里就要讲一下 ' 和 " 区别
在SQL 语句里 ' 是使用在文本型中 如 '文本' '张三'
" 是用在数字型中 如 "12" "45"
值得注意的是 '12' 和 "12" 是有本质不同的 前面的是文本不能加减运算; 后面"12" 是数字型可以加减运算
##### 帮你注释一下吧 #####
If Combo1.Text = "进价" Or Combo1.Text = "数量" Or Combo1.Text = "金额" Then '//判断选择的是 进价或数量或金额则执行以下操作
Set rs = conn.Execute("select * from purchase where " & Combo1.Text & "=" & Combo2.Text) '// 因为进价或数量或金额都是数字型(后面可能要进行加减运算)所以执行这条.
Else
Set rs = conn.Execute("select * from purchase where " & Combo1.Text & "='" & Combo2.Text & "'") '//其它的应该是文本型所以执行这条.
End If