存储过程output String[1]: Size 属性具有无效大小值0
c#代碼:
using (SqlConnection sqlcon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlGwRegister"].ConnectionString.ToString()))
{
sqlcon.Open();
// SqlCommand cmd = new SqlCommand("Pro_Sof_CheckMaterial", sqlcon);
SqlCommand cmd = new SqlCommand("Pro_Sof_CheckMaterial_test", sqlcon);
cmd.CommandType = CommandType.StoredProcedure;
// cmd.Parameters.Add( new SqlParameter("@Year", SqlDbType.NVarChar));
cmd.Parameters.Add("@Year", SqlDbType.NVarChar);
cmd.Parameters["@Year"].Value = year;
// cmd.Parameters.Add(new SqlParameter("@Batch", SqlDbType.NVarChar));
cmd.Parameters.Add("@Batch", SqlDbType.NVarChar);
cmd.Parameters["@Batch"].Value = batch;
//cmd.Parameters.Add(new SqlParameter("@OutMaterial", SqlDbType.NVarChar));
cmd.Parameters.Add("@OutMaterial", SqlDbType.NVarChar, 4000);
cmd.Parameters["@OutMaterial"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
msg = cmd.Parameters["@OutMaterial"].Value.ToString();
}
执行存储过程出现这个错误:存储过程output String[1]: Size 属性具有无效大小值0
解決要點:output方式从存储过程传出参数 必须使用三个参数版本的,及Parameters.Add("("@OutMaterial", SqlDbType.VarChar,4000);