zoukankan      html  css  js  c++  java
  • 存储过程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);

    多一分冷靜,少一分浮躁
  • 相关阅读:
    Understanding identities in IIS
    Name your feature branches by convention
    Branch policies on Azure Repos
    Use Git Credential Managers to Authenticate to Azure Repos
    How do I force my .NET application to run as administrator?
    UML的类型
    ASP.NET Error Handling
    通过泛型,将string转换为指定类型
    Spring Session + Redis实现分布式Session共享
    MongoDB中的数据导出为excel CSV 文件
  • 原文地址:https://www.cnblogs.com/AnnyGird-LiMing/p/4998356.html
Copyright © 2011-2022 走看看