MemberChecker.CommandType = CommandType.StoredProcedure;
添加 并解决了问题!
---- 这是一个有趣的问题!
为什么我的 SqlCommand 访问存储过程仅在我使用时才有效
ParameterDirection.InputOutput
并不是
ParameterDirection.Output
此 SqlParameterCollection 不包含具有 ParameterName '@Customer' 的 SqlParameter
这是我的一些代码:
using (SqlConnection H20_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["H20"].ConnectionString))
{
SqlCommand MemberChecker = new SqlCommand("execute custom_x_Check", H20_Connection);
MemberChecker.Parameters.Add("@TN", SqlDbType.VarChar,50).Value = TNH20.Text.Trim();
MemberChecker.Parameters.Add("@Customer_ID", SqlDbType.VarChar, 50).Value = TNH20.Text.Trim();
MemberChecker.Parameters.Add("@Customer", SqlDbType.VarChar, 100).Direction = ParameterDirection.Output;
MemberChecker.Parameters.Add("@Out_TN", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
MemberChecker.Parameters.Add("@Out_Customer_ID", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
H20_Connection.Open();
if (MemberChecker.ExecuteNonQuery() > 1)
{
Top.Visible = false;
Bottom.Visible = true;
}
else
{
Top.Visible = true;
Bottom.Visible = false;
}
}
和我的 SQL
alter proc custom_Check
@TN varchar(50) ='',
@Customer_ID varchar(50)='',
@Customer varchar(100) out,
@Out_TN varchar(50) out,
@Out_Customer_ID varchar(50) out
as
select @Out_Customer_ID=Customer_ID,
@Out_TN = MainTN,@Customer = Customer
from [vCustomerName]
where Customer_ID = @Customer_ID or @TN = MainTN
谢谢!