两条语句的区别???急~~~
来源:百度知道 编辑:UC知道 时间:2024/04/28 06:48:43
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 & "'") 的区别在哪里??
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 & "'") 的区别在哪里??
区别就在于参数的数据类型
("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 & "=" & Combo