在页面加载中我添加了如下参数 protected void Page_Load(object-6ren">
gpt4 book ai didi

c# - 必须声明标量变量 "@LoggedInUser"。尝试向 SqlDataSource 添加参数时出错

转载 作者:太空狗 更新时间:2023-10-30 00:15:53 25 4
gpt4 key购买 nike

我正在使用 SqlDataSource 来显示基于登录用户的记录,

<asp:SqlDataSource ID="ModifyCustomerDataSource" SelectCommand="SELECT cApplicationNo,cFirstName,cMiddleName,cLastName,nTelNo,nMobileNo,cPanGirNo from Data_Customer_Log where cAddedBy=@LoggedInUser" ConnectionString="<%$ ConnectionStrings:CwizDataConnectionString %>"   runat="server"></asp:SqlDataSource>

在页面加载中我添加了如下参数

protected void Page_Load(object sender, EventArgs e)
{
string user = HttpContext.Current.User.Identity.Name;
ModifyCustomerDataSource.SelectParameters.Clear();
ModifyCustomerDataSource.SelectParameters.Add("@LoggedInUser", user.Trim());
}

但它给我错误

Must declare the scalar variable "@LoggedInUser".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@LoggedInUser".

任何人都可以指出我哪里出错了。谢谢

最佳答案

添加参数时不需要@ eg:

ModifyCustomerDataSource.SelectParameters.Add("LoggedInUser", user.Trim());

查询中的@ 符号表示后面的文本是参数名称,但是@ 不被视为参数名称的一部分。

关于c# - 必须声明标量变量 "@LoggedInUser"。尝试向 SqlDataSource 添加参数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10633065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com