陕西论坛汽车之家:sql查询语句
来源:百度文库 编辑:杭州交通信息网 时间:2024/05/10 19:21:06
请问查询条件是变量的时候SQL语句怎么写啊
比如crname=Session("tempname")
然后查询语句怎么写呢,是下面的吗?
Dim cmd As New OleDbCommand("select * from userinfo Where uname ='"&crname"'" , conn)
我用‘12345’之类的替换查询条件就可以成功,一换成变量就失败了,达人来解惑啊
少打一个&的结果-_-
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC32017: Comma, ')', or a valid expression continuation expected.
Source Error:
Line 7: Dim crname As String
Line 8: crname=Session("tempname")
Line 9: Dim cmd As New OleDbCommand("select * from userinfo Where uname ='"&crname"'" , conn)
Line 10: conn.Open()
Line 11: Dim dr As OleDbDataReader = cmd.ExecuteReader()
Source File: C:\Inetpub\wwwroot\myjob\log\seccuss.aspx Line: 9
比如crname=Session("tempname")
然后查询语句怎么写呢,是下面的吗?
Dim cmd As New OleDbCommand("select * from userinfo Where uname ='"&crname"'" , conn)
我用‘12345’之类的替换查询条件就可以成功,一换成变量就失败了,达人来解惑啊
少打一个&的结果-_-
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC32017: Comma, ')', or a valid expression continuation expected.
Source Error:
Line 7: Dim crname As String
Line 8: crname=Session("tempname")
Line 9: Dim cmd As New OleDbCommand("select * from userinfo Where uname ='"&crname"'" , conn)
Line 10: conn.Open()
Line 11: Dim dr As OleDbDataReader = cmd.ExecuteReader()
Source File: C:\Inetpub\wwwroot\myjob\log\seccuss.aspx Line: 9
("select * from userinfo Where uname ='"&crname&"'" , conn)
response.write ("select * from userinfo Where uname ='"&crname"'")
response.end
然后检查是那错了
("select * from userinfo Where uname ='"&crname"'" , conn)
crname后少一个&
("select * from userinfo Where uname ='"&crname&"'" , conn)
少一个&