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