Click here to Skip to main content
15,909,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
{
    SqlParameter p = default(SqlParameter);
    foreach ( p in commandParameters) {
        // check for derived output value with no value assigned
        if (((p.Direction == ParameterDirection.InputOutput) && (p.Value == null))) {
            p.Value = null;
        }
        command.Parameters.Add(p);
    }
}
Posted
Updated 17-Jul-14 3:03am
v2
Comments
[no name] 17-Jul-14 8:12am    
Yes.... very nice unformatted code. Was there anything else?
Sathish kumar M S 17-Jul-14 8:24am    
showing same error

1 solution

Hello,


C#
foreach (SqlParameter parameter in commandParameters) {
        // check for derived output value with no value assigned
        if (((parameter.Direction == ParameterDirection.InputOutput) && (parameter.Value == null))) {
            parameter.Value = null;
        }
        command.Parameters.Add(parameter);
    }

and remove:
SqlParameter p = default(SqlParameter);




Valery.
 
Share this answer
 
Comments
Sathish kumar M S 17-Jul-14 9:23am    
Its working Thank you Valery!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900