2014-10-16 60 views
1

我正在使用通过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',该参数未提供。”我能得到一些帮助吗?

+0

如果我的答案(如下)解决了您的问题,请将其标记为“已接受答案”(绿色V),同时您也获得2个声望。 – Jacob 2014-10-17 02:46:48

回答

1

你应该从你的C#代码提供用户ID给您的存储过程是这样的:

cmd.Parameters.Add("@UserId", SqlDbType.bytes).Value = txtUserId.Text; 

林不知道有关SqlDbType.bytes因为我不是附近的Visual Studio的时刻,但它应该是这样的那。

+0

谢谢,问题已解决,为迟到的答复道歉,刚从小型假期回来。再次感谢! – 2014-10-21 12:47:26

相关问题