Output parameter not returned from stored Proc

I call SQL-proc which has 3 OUTPUT parameters. After calling proc, one of the parameters does not return a value when the other two do. The profiler shows that all 3 values ​​are returned.

Parameters are declared as follows in proc ...

@UsrVariableID INT OUTPUT,
@OrganisationName NVARCHAR(256) OUTPUT,
@Visible bit OUTPUT

and the code that calls proc looks like this:

cm.Parameters.AddWithValue("@OrganisationName", name);
cm.Parameters["@OrganisationName"].Direction = ParameterDirection.Output;
cm.Parameters.AddWithValue("@Visible", visible);
cm.Parameters["@Visible"].Direction = ParameterDirection.Output;

cm.ExecuteNonQuery();

name = cm.Parameters["@OrganisationName"].Value.ToString();
visible = bool.Parse(cm.Parameters["@Visible"].Value.ToString());
id = int.Parse(cm.Parameters["@UsrVariableID"].Value.ToString());

The parameter that fails is @OrganisationName.

I am wondering if this is because the parameter has a type string in the code, but NVARCHAR in proc.

Does anyone have any ideas?

+3
source share
7 answers

, (nvarchar, varchar ..), , . , , #. , , , :

SqlParameter theOrganizationNameParam = new SqlParameter( "@OrganisationName", SqlDbType.NVarChar, 256 );
theOrganizationNameParam.Direction = ParameterDirection.Output;
cm.Parameters.Add( theOrganizationNameParam );
cm.ExecuteNonQuery();
name = theOrganizationNameParam.Value;

, , , .

, .

+5

( ) , .

cm.Parameters.Add["@OrganisationName", SqlDbType.NVarChar, 256].Direction = ParameterDirection.Output
cm.Parameters["@OrganisationName"].Value = name

, - , .

, .Parse(.ToString()), .

visible = bool.Parse(cm.Parameters["@Visible"].Value.ToString());

visible = (bool)cm.Parameters["@Visible"].Value;
+2

100% MS SQL, .NET → Oracle .

cm.Parameters["@OrganisationName"].Size = 256;
+1

, , , . , .

0

, .

.

cm.Parameters["@OrganisationName"].Size = 50;

- , , .

, nvarchar (max). SELECT, .

0

, , , : .

, nvarchar (7), #.NET = 255, , 7 ....

, ... ...

0

Source: https://habr.com/ru/post/1698882/


All Articles