1、打開sql企業管理器,在裡面建立數據庫userinfo,完成後再在這個數據庫中建立表user,再建立字段username、passWord,字段類型(varchar),最後給這個數據庫加個用戶user,設置好密碼。向表中輸入兩條記錄或更多,用來測試
2、打開userinfo ------- 存儲過程------右擊-----新建存儲過程(getUserlogin)-----刪除文本框中的內容,貼粘上以下代碼:
CREATE PROCEDURE dbo.getUserlogin
@UserName varchar(40),
@UserPass varchar(40) output
as
set nocount on
begin
if @UserName is null return
select @UserPass=passWord
from dbo.[user]
where username=@UserName
return
end
GO
3、conn.ASP
<%
dim conn,connstr
set conn = server.createobject("adodb.connection")
connstr="Provider=SQLOLEDB.1;Persist Sercurity Info=True;User ID=user;pwd=123456;Initial Catalog=userinfo;Data Source=(local);"
conn.open connstr
set rs=server.CreateObject("adodb.recordset")
%>
4、用戶登錄窗口 index.htm
<form name="form1" method="post" action="login.ASP">
<input type="text" name="username"><br>
<input type="password" name="passWord"><br>
<input type="submit" value=" 登 錄 ">&nbsp;<input type="reset" value="重置">
</form>
5、login.ASP
<!--#include file="conn.ASP"-->
<%
username=request("username")
password=request("passWord")
'**調用帶有輸入輸出參數的存儲過程**
DIM MyComm,UserName
Set MyComm = Server.CreateObject("ADODB.Command")
MyComm.ActiveConnection = conn
MyComm.CommandText = "getUserlogin" '指定存儲過程名
MyComm.CommandType = 4 '表明這是一個存儲過程
MyComm.Prepared = true '要求將SQL命令先行編譯
'聲明參數
MyComm.Parameters.append MyComm.CreateParameter("@UserName",200,1,40,username)
MyComm.Parameters.append MyComm.CreateParameter("@UserPass",200,2,40)
MyComm.Execute
'取得出參
UserPass = MyComm(1)
If passWord=userpass Then
response.write "登錄成功"
Else
response.write "登錄失敗"
End if
Set MyComm = Nothing
%>
6、IIS中運行index.htm,看看效果