当前位置: 代码迷 >> ASP >> asp中怎么用变量来代替字段
  详细解决方案

asp中怎么用变量来代替字段

热度:91   发布时间:2012-05-23 13:44:13.0
asp中如何用变量来代替字段
就是说在asp+access中,查询数据库,我想用从表单中获取的变量来代替sql语句中where后面的字段,具体的语法是怎么样?
<%
type_select=request.Form("type_select")
type_area=request.Form("type_area")
response.Write type_select&type_area
set rs=Server.CreateObject("ADODB.recordset")
sql="select * from stu where '&type_select&'='&type_area&'"
rs.open sql,conn

if rs.eof and rs.bof then
response.Write "no"
else
response.Write rs("stu_num")
end if
%>

求高手指点啊

------解决方案--------------------
sql="select * from stu where "&type_select&"='"&type_area&"'"
------解决方案--------------------
sql="select * from stu where 1 = 1"
if type_select <> "" then
sql = sql & "type_select = '"&type_select&"'"
end if
if type_area <> "" then
sql = sql & "type_area = '"&type_area&"'"
end if


楼主 这个意思?


------解决方案--------------------
sql="select * from stu where 1=1 " & type_select & "='" & type_area & "'"
拼sql很简单
  相关解决方案