Asp中IF语句的嵌套使用
- 格式:pdf
- 大小:68.95 KB
- 文档页数:3
'==========IF2 语句开
response.write"已经存在此用户名!" Else If rsuser.eof Then Set rsUser = Nothing
开始
'==========IF3 语句
'在数据库表 Users 中插入新用户信息
sql="INSERT INTO Users (UserName, UserPwd)
Asp 中 IF 语句的嵌套使用
asp 中的 if 多重嵌套使用,有时也能给我们带来特殊的作用,但是用不好的话,就会出错。 今天我把 if 的嵌套使用方法总结一下。希望能让大家了解一下 if 嵌套的使用方法。
If …… Then If …… Then Else …… End If
ElseIf If …… Then Else ……
response.write"用户添加成功!"
End if
' ==================== IF2 语句结束
end if
Else '更新用户信息 sql = "UPDATE Users SET username='"&vusername&"' Where
Userid='"&vUserId&"'" Conn.Execute(sql)
举例如下:
If vusername<>"" Then
'==================IF1 语句开始
'判断此用户是否存在
Set rsUser = conn.Execute("Select * From users Where
username='"&vusername&"'")
If Not rsUser.EOF Then 始
response.write"用户信息更改成功!"
End if
'==============IF1 语句结束
பைடு நூலகம்
'==========IF2 语句 '==========IF3 语句开始
'在数据库表 Users 中插入新用户信息
sql="INSERT INTO Users (UserName, UserPwd)
VALUES('"&vusername&"','"&vuserpwd&"')"
Conn.Execute(sql)
'判断此用户是否存在
Set rsUser = conn.Execute("Select * From users Where
username='"&vusername&"'")
If Not rsUser.EOF Then 开始
response.write"已经存在此用户名!" Else If rsuser.eof Then Set rsUser = Nothing
Userid='"&vUserId&"'"
Conn.Execute(sql)
response.write"用户信息更改成功!"
End if
'==============IF1 语句结束
也可以写成下面的代码,
If vusername<>"" Then
'==================IF1 语句开始
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 ,要是不加的话就会出错的,我刚试过了的。
VALUES('"&vusername&"','"&vuserpwd&"')"
Conn.Execute(sql)
response.write"用户添加成功!"
End if
' ==================== IF2 语句结束
Else
'更新用户信息
sql = "UPDATE Users SET username='"&vusername&"' Where