繁体   English   中英

过程或函数预期未提供参数错误

[英]Procedure or Function expects parameter error which was not supplied

我使用的是通过ASP.NET Configuration Manager创建的数据库,登录后,我有一个页面在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'。” 我可以帮忙吗?

您应该像这样从C#代码向存储过程提供UserId:

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

我不确定SqlDbType.bytes因为我目前不在Visual Studio附近,但应该是类似的东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM