C# 必须声明标量变量"@LoggedInUser";。尝试将参数添加到SqlDataSource时出错

C# 必须声明标量变量"@LoggedInUser";。尝试将参数添加到SqlDataSource时出错,c#,sqldatasource,C#,Sqldatasource,我正在使用SqlDataSource显示基于登录用户的记录 <asp:SqlDataSource ID="ModifyCustomerDataSource" SelectCommand="SELECT cApplicationNo,cFirstName,cMiddleName,cLastName,nTelNo,nMobileNo,cPanGirNo from Data_Customer_Log where cAddedBy=@LoggedInUser" ConnectionString="

我正在使用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>
但它给了我错误

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".
谁能告诉我哪里出了问题。
谢谢

添加参数时不需要
@
,例如:

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

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

这是使用sqldatasource的最佳实践吗?只是好奇。我在不使用sqldatasource的情况下工作。如果您想要示例代码,请让我知道。@AnandMohanAwasthi,我正在将这些数据绑定到我的jqGrid,因此这对我来说是一种更简单的方法,我不太清楚这是不是最佳实践,您能向rich okelly询问一下吗。示例代码将帮助我。谢谢问题已经解决,rich的回答很有帮助。感谢您的回答。ModifyCustomerDataSource.SelectParameters.Add(“@LoggedInUser”,user.Trim()),不起作用,删除@worked for meIt起作用了,因为根据我的示例,您没有在aspx中提到“LoggedInUser”的标记。今晚,由于这个原因,时间太长了,单词太多了。
<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">

        <SelectParameters>

            <asp:Parameter Name="LoggedInUser" />

        </SelectParameters>

</asp:SqlDataSource>
ModifyCustomerDataSource.SelectParameters["LoggedInUser"].DefaultValue = "some value";

or

ModifyCustomerDataSource.SelectParameters.Add("@LoggedInUser", user.Trim()); //@is must here with the parameter name
ModifyCustomerDataSource.SelectParameters.Add("LoggedInUser", user.Trim());