我正在使用通过ASP.NET配置管理器创建的数据库,登录后,我有一个页面显示用户的客户端在GridView中,但我只希望用户只能看到他们各自的客户。过程或函数期望参数错误,但未提供
//代码:
protected void Page_Load(object sender, EventArgs e)
{
String strConnString = ConfigurationManager.ConnectionStrings["BA_2014ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "getClients";
cmd.Connection = con;
con.Open();
gvClients.DataSource = cmd.ExecuteReader();
gvClients.DataBind();
con.Close();
con.Dispose();
}
//存储过程:
ALTER PROCEDURE dbo.getClients
@UserId uniqueidentifier
AS
BEGIN
SELECT ClientId, UserId, ClientName, EmailAddress, PhoneNumber, ServicesNum FROM Client_tb WHERE @UserId = UserId
END
...当我删除where子句,GridView控件显示所有的客户。但是,如果where子句存在,我会得到以下错误:“过程或函数'getClients'期望参数'@UserId',该参数未提供。”我能得到一些帮助吗?
如果我的答案(如下)解决了您的问题,请将其标记为“已接受答案”(绿色V),同时您也获得2个声望。 – Jacob 2014-10-17 02:46:48