无法更新归档的lastlogin [英] unable to update filed lastlogin

查看:64
本文介绍了无法更新归档的lastlogin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

login.cs

login.cs

boolReturnValue = true;
Session["UserId"] = dt.Rows[0]["Id"].ToString();
string updateLastLogin = "UPDATE [User] SET LastLogon = GETDATE() where Id= @UserId";
dbClass.ConnectDataBaseToInsert(updateLastLogin);



错误来了
必须声明标量变量"@UserId".



error comes
Must declare the scalar variable "@UserId".

推荐答案

没有看到您的dbClass定义,这很难精确,但是我会添加一个重载:
Without seeing your dbClass definition, it is difficult to be precise, but I would add an overload:
dbClass.ConnectDataBaseToInsert(updateLastLogin, "@userID", Session["UserId"]);

除非您的类已经设置了用于添加属性的方法.
请不要将其转换为连接的字符串,因为它会使您很容易通过用户ID进行SQL注入攻击.

unless your class already has a method set up for adding properties.
Please, do not convert this to a concatenated string as it leave you wide open for an SQL Injection attack via the user ID.


您在哪里定义了@UserId,因为它是一行字符串查询,您需要放置值而不是@UserId.

应该像
Where have you defined @UserId, since it is a single line string query, you need to put value instead of @UserId.

It should be like
string updateLastLogin = "UPDATE [User] SET LastLogon = GETDATE() where Id= " + Session["UserId"].ToString();


您会收到错误消息,因为即使未声明@UserId,您仍在引用它.当您使用自己的数据访问层时,我将@UserId替换为您在上一行的Session中输入的ID值.
you''re getting the error because you''re referencing @UserId even though it hasn''t been declared. As you''re using your own data access layer I''d replace the @UserId with the Id value you put in Session on the previous line.


这篇关于无法更新归档的lastlogin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆