[英]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.