当前位置:编程学习 > asp >>

ASP中,我要查询或取出数据库的一个字段里的值,然后根据这个字段的值来判断用哪种方式显示。请问要怎么写

ASP中,我要查询或取出数据库的一个字段里的值,然后根据这个字段的值来判断用哪种方式显示。请问要怎么写? 我是这么写的: if conn.execute("Select top 1 字段 From 数据库 Where 字段=' 1 '").eof Then '显示为真 Else '显示为假 可是我写出来后,一直都是显示Else的值。。 我知道我写的查询语句肯定有错,但是不知道究竟该怎么写。
补充:RS未定义是咋回事呀?还有,三楼的第一句有问题,要怎么结束呢?
追问:The EOF property returns True (-1) if the current record position is after the last record in the Recordset, otherwise it returns False (0). 

我用加上这句后,提示语句未完整,指针指在property 这儿。我不是很理解这句是什么意思。能说下么?
答案:set rs = server.CreateObject("adodb.recordset")
sql = "select id,name,sex  from user_info "
rs.open sql,conn,adOpenStatic,adLockReadOnly,adCmdTxt
if not rs.eof then
    do while not rs.eof 
          if rs("sex") = 0 then
              response.write("男")
          else
              response.write("女")
         end if
    rs.movenext
    loop
else
    response.write("no data")
end if 
-------------------
用完关闭,是我忘记写了不好意思
rs.close
set rs = nothing
页面最后还要关闭数据库链接
Conn.Close
Set Conn=Nothing
其他:先连接数据库
然后 rs("表名")提取
判断可以
if rs("表名")=1 then
输出..
else
输出..
end if asp,怎样在数据库中一个字段里写入多个值,格式是怎么样的,然后可以在比如, 写入字段就是 红,黑,白调用的时候用split这个函数分割就好了 dim The EOF property returns True (-1) if the current record position is after the last record in the Recordset, otherwise it returns False (0). 

 if(conn.execute("Select top 1 字段 From 数据库 Where 字段=' 1 '").eof==FALSE) Then
...
else
....
end if 
写入的时候加个间隔符号 比如,
写入字段就是 红,黑,白
调用的时候用split这个函数分割就好了
dim str,sp
str=数据库字段
sp=split(str,",")
<select name="color">
<%for i=0 to ubound(sp)%>
<option value=<%=sp(i)%>><%=sp(i)%></option>
<%next%>
</select>

例子就和实际情况一样的 存如数据库的时候也是把数据连一起的 

上一个:ASP.NET中下载代码怎么写
下一个:在asp2005中提示“无法连接到visual studio的local web服务器”你是怎么解决的?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,