我正在使用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>
Run Code Online (Sandbox Code Playgroud)
在页面加载中,我添加了如下参数
protected void Page_Load(object sender, EventArgs e)
{
string user = HttpContext.Current.User.Identity.Name;
ModifyCustomerDataSource.SelectParameters.Clear();
ModifyCustomerDataSource.SelectParameters.Add("@LoggedInUser", user.Trim());
}
Run Code Online (Sandbox Code Playgroud)
但它给了我错误
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".
Run Code Online (Sandbox Code Playgroud)
任何人都可以指出我出错的地方.谢谢
Ric*_*lly 10
@添加参数时不需要添加参数,例如:
ModifyCustomerDataSource.SelectParameters.Add("LoggedInUser", user.Trim());
Run Code Online (Sandbox Code Playgroud)
@查询中的符号表示以下文本是参数的名称,但@不会将其视为参数名称的一部分.