您当前的位置: 首页 > 网站编程 > ASP教程 > asp中的if多重嵌套的使用

asp中的if多重嵌套的使用

作者:admin 来源:不详 发布时间: 2008-06-04 08:50 点击:
asp中的if多重嵌套使用,有时也能给我们带来特殊的作用,但是用不好的话,就会出错。今天我把if的嵌套使用方法总结一下。希望能让大家了解一下if嵌套的使用方法。 If……Then If……Then Else …… EndIf ElseIf If……Then Else …… EndIf Else If……Then

asp中的if多重嵌套的使用

    asp中的if多重嵌套使用,有时也能给我们带来特殊的作用,但是用不好的话,就会出错。今天我把if的嵌套使用方法总结一下。希望能让大家了解一下if嵌套的使用方法。 
If …… Then 
        If …… Then 
         Else 
         …… 
        End If 
ElseIf 
         If …… Then 
         Else 
         …… 
         End If 
Else 
        If …… Then 
        Else 
          …… 
        End If 
End If 

这里还要注意一下,
if    then     end if这组语句用法不是固定的
如果是
if A then B
就不用end if,有则出错
如果是
if A     then
B
那么下面就要加end if ,要是不加的话就会出错的,我刚试过了的。举例如下:If vusername<>"" Then              ’==================IF1语句开始
         ’判断此用户是否存在
         Set rsUser = conn.Execute("Select * From users Where username=’"&vusername&"’")
      
         If Not rsUser.EOF Then                        ’==========IF2语句开始
     response.write"已经存在此用户名!" 
         Else If rsuser.eof Then Set rsUser = Nothing     ’==========IF3语句开始
       
            ’在数据库表Users中插入新用户信息
       sql="INSERT INTO Users (UserName, UserPwd) VALUES(’"&vusername&"’,’"&vuserpwd&"’)"
     Conn.Execute(sql)
         response.write"用户添加成功!"
         End if                ’ ==================== IF2语句结束  
       
   
     Else
       ’更新用户信息
       sql = "UPDATE Users SET username=’"&vusername&"’ Where Userid=’"&vUserId&"’"
        Conn.Execute(sql)
     response.write"用户信息更改成功!"
     End if                     ’==============IF1语句结束 也可以写成下面的代码,If vusername<>"" Then              ’==================IF1语句开始
         ’判断此用户是否存在
         Set rsUser = conn.Execute("Select * From users Where username=’"&vusername&"’")
      
         If Not rsUser.EOF Then                         ’==========IF2语句开始
     response.write"已经存在此用户名!" 
         Else If rsuser.eof Then                  ’==========IF3语句开始            Set rsUser = Nothing        
       
            ’在数据库表Users中插入新用户信息
       sql="INSERT INTO Users (UserName, UserPwd) VALUES(’"&vusername&"’,’"&vuserpwd&"’)"
     Conn.Execute(sql)
         response.write"用户添加成功!"
         End if                ’ ==================== IF2语句结束  
        end if
   
     Else
       ’更新用户信息
       sql = "UPDATE Users SET username=’"&vusername&"’ Where Userid=’"&vUserId&"’"
        Conn.Execute(sql)
     response.write"用户信息更改成功!"
     End if                     ’==============IF1语句结束 
分享到:
本文"asp中的if多重嵌套的使用"由远航站长收集整理而来,仅供大家学习与参考使用。更多网站制作教程尽在远航站长站。
顶一下
(3)
100%
踩一下
(0)
0%
[点击 次] [返回上一页] [打印]
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
关于本站 - 联系我们 - 网站声明 - 友情连接- 网站地图 - 站点地图 - 返回顶部
Copyright © 2007-2013 www.yhzhan.com(远航站长). All Rights Reserved .
远航站长:为中小站长提供最佳的学习与交流平台,提供网页制作与网站编程等各类网站制作教程.
官方QQ:445490277 网站群:26680406 网站备案号:豫ICP备07500620号-4