两条语句的区别?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/06/28 15:43:56
![两条语句的区别?If Combo1.Text =](/uploads/image/z/10101372-60-2.jpg?t=%E4%B8%A4%E6%9D%A1%E8%AF%AD%E5%8F%A5%E7%9A%84%E5%8C%BA%E5%88%AB%3FIf+Combo1.Text+%3D+%22%E8%BF%9B%E4%BB%B7%22+Or+Combo1.Text+%3D+%22%E6%95%B0%E9%87%8F%22+Or+Combo1.Text+%3D+%22%E9%87%91%E9%A2%9D%22+ThenSet+rs+%3D+conn.Execute%28%22select+%2A+from+purchase+where+%22+%26+Combo1.Text+%26+%22%3D%22+%26+Combo2.Text%29ElseSet+rs+%3D+conn.Execute%28%22select+%2A+from+purchase+where+%22)
两条语句的区别?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