AddOutParameter causes Type Problems

Source: Internet
Author: User

1 Database db = DatabaseFactory. CreateDatabase (connString );
2 DbCommand dbCommand = db. GetStoredProcCommand (sp );
3
4 db. AddOutParameter (dbCommand, "@ RetCode", DbType. String, 4); <--- errors are always reported here, and type conversion is faulty.
5 db. AddInParameter (dbCommand, "@ Room", DbType. Int32, XXXX );
6
7
8 db. ExecuteNonQuery (dbCommand );
9
10 return db. GetParameterValue (dbCommand, "@ RetCode"). ToString ();
11

The stored procedure has an output parameter varchar (4)
Use the Enterprise Library-June 2005 to call this stored procedure. One line of code is as follows:
Db. AddOutParameter (dbCommand, "@ RetCode", DbType. String, 4 );

So where is the problem?

Google's half-day results may be caused by DbType. String.

Http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/cpref/html/frlrfsystemdatadbtypeclasstopic. asp

DbType. String
A type representing Unicode character strings.

DbType. AnsiString
A variable-length stream of non-Unicode characters ranging between 1 and 8,000 characters.

If your parameter type is varchar, you should use DbType. AnsiString. If it is nvarchar, DbType. String should be used.

However, for this reason, "the current command has encountered a serious error. Discard any possible results. "
"A general network error occurs. Check your network documentation. This exception is too easy to mislead
I changed:

SqlParameter sqlParameter = new SqlParameter ("@ RetCode", SqlDbType. varchar, 4 );

Result OK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.