Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
If I Pass the output parameter to the Sqlparameter Array type

C#
SqlParameter[] parameters = {
   new SqlParameter("@RoleTypeCode",objRoleType.RoleTypeCode),
   new SqlParameter("@RoleTypeDesc",objRoleType.RoleTypeDesc),
   new SqlParameter("@OutMsg",objRoleType.OutMessage).Direction=ParameterDirection.Output // here i got error


I got below Error

Cannot implicitly convert type 'System.Data.ParameterDirection' to 'System.Data.SqlClient.SqlParameter'

Please help me for the same to pass output parameter to sqlparameter[] array in ado.net

Regards,
Ravi Sharma
Posted
Updated 13-May-13 20:39pm
v2

use this..

C#
SqlParameter[] parameters = {
new SqlParameter("@RoleTypeCode",1),
new SqlParameter("@RoleTypeDesc",1),
new SqlParameter("@OutMsg",1)  };

parameters[2].Direction=ParameterDirection.Output;


let me know if any problem....
 
Share this answer
 
v2
Comments
Ravi Sharma 2 14-May-13 4:31am    
Now i got below Error on sqlHelper Class File.

String[2]: the Size property has an invalid size of 0

my stored procedure return varchar value as a outpur parameter.
AnkitGoel.com 14-May-13 6:21am    
use this...
string str= "value";

SqlParameter[] parameters = {
new SqlParameter("@RoleTypeCode",1),
new SqlParameter("@RoleTypeDesc",1),
new SqlParameter("@OutMsg",str) };

parameters[2].Direction=ParameterDirection.Output;

OR


SqlParameter[] parameters = {
new SqlParameter("@RoleTypeCode",1),
new SqlParameter("@RoleTypeDesc",1),
new SqlParameter("@OutMsg",1) };

parameters[2].Direction=ParameterDirection.Output;
parameters[2].Size = 20 //Required Size in bytes, 20 is just an example.
Hi,

I think this works for you, I done by this way

SQL
SqlParameter outPutVal = new SqlParameter("@ID", SqlDbType.Int);
outPutVal.Direction = ParameterDirection.Output;
 
Share this answer
 

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