This article is a mirror article of machine translation, please click here to jump to the original article.

View: 20045|Reply: 0

[Source] String[3]: the Size property has an invalid size of 0.

[Copy link]
Posted on 10/26/2015 9:39:40 AM | | |
When calling a stored procedure in a C# program, a strange exception String[3]: the Size property has an invalid size of 0.

The stored procedure that has this problem is characterized by the presence of out parameters of type varchar or nvarchar

The definition of this parameter at the time of call is similar to
SqlParameter para = new SqlParameter("@paraname", DBType.String);


Workaround: The out parameter must have a specified length, so it should be initialized like this:
SqlParameter para = new SqlParameter("@paraname", DBType.String, size);

  1. DBHelper db = new DBHelper();
  2.             SqlParameter[] param = new SqlParameter[5];
  3.             param[0] = new SqlParameter("ID", SqlDbType.Int);
  4.             param[0].Direction = ParameterDirection.Output;
  5.             param[1] = new SqlParameter("UserID", userid);
  6.             param[2] = new SqlParameter("UserName", SqlDbType.NVarChar, 50);
  7.             param[2].Direction = ParameterDirection.Output;
  8.             param[3] = new SqlParameter("Password", pass);
  9.             param[4] = new SqlParameter("Result", SqlDbType.Int);
  10.             param[4].Direction = ParameterDirection.Output;

  11.             var spc = db.Crm_ExecuteNonQueryReturns("pUserLogin",param);
Copy code






Previous:Compare the performance of the primary key of the Guid field using the self-incremental field in the library
Next:One question about serialization and deserialization
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com