2016-09-03 92 views
0

我想用C#代碼調用一個非常簡單的SQL Server存儲過程。我有一個有authenticate方法的類。我傳遞文本框的值(用戶名,密碼)到這個方法,它不斷拋出我關於所需的參數不傳遞錯誤。我基本上是從事C#項目的商業智能專家。幫助將不勝感激。用參數調用SQL Server存儲過程使用C#

這裏是代碼我執行:

sqcon.Open(); 

SqlCommand cmd = new SqlCommand("Users.PR_Authenticate_WebUsers",sqcon); 

cmd.Parameters.Add("@In_UserID", SqlDbType.VarChar).Value = "f"; 
cmd.Parameters.Add("@In_PassWord", SqlDbType.NVarChar).Value = "f"; 
cmd.Parameters.Add("@Out_IsAuthenticatedUser", SqlDbType.Bit); 
cmd.Parameters["@Out_IsAuthenticatedUser"].Direction = ParameterDirection.Output; 

cmd.ExecuteNonQuery(); 
sqcon.Close(); 

當我傳遞的參數值明確爲什麼抱怨值沒有傳遞我不明白?我錯過了什麼嗎?

+0

做u得到一些錯誤?向我們展示完整代碼 – BNN

回答

2

嗯看起來像你說的不是命令對象,它是一個存儲過程不是一個普通的查詢,試試這個

sqcon.Open(); 
    SqlCommand cmd = new SqlCommand("Users.PR_Authenticate_WebUsers",sqcon); 
    cmd.CommandType = CommandType.StoredProcedure; 

    //Add parameters like this 
    cmd.Parameters.Add(new SqlParameter("@In_UserID", "f")); 
    sqcon.Close() 
+0

感謝Sir marc_s –

+0

感謝Zain UI Abidin。有效。 – user6789854

相關問題