Asp中IF语句的嵌套使用
Asp中IF语句的嵌套使用
asp中的if多重嵌套使用,有时也能给我们带来特殊的作用,但是用不好的话,就会出错。
今天我把if的嵌套使用
方法
快递客服问题件处理详细方法山木方法pdf计算方法pdf华与华方法下载八字理论方法下载
总结一下。希望能让大家了解一下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语句结束