Size of IDataParameter for OUTPUT sp parameter

  • Thread starter Thread starter mawi
  • Start date Start date
M

mawi

Hi there,

idataparameter does not have a size property (for
string/varchar parameters), and without setting it it will
not return a value.

If I temporarily cast the idataparameter to a sqlparameter
and set the size, all works well.

My code is like so (sketch):
IDbConnection [...] // create a sql connection, sql server
for example
IDbCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "aStoredProcedureName";
IDataParameter para = cmd.CreateParameter();
para.ParameterName = "@someOutParameter";
// (para as SqlParameter).Size = 20; // <--- works if included
para.Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery;
Console.Write( Convert.ToString( para.Value );


Now, this actually exists in a certain layer so this code
does not convey the design, obviously.

What is the solution to this? The IData/Db interfaces have
worked fine so far as an abstraction layer, it does not
seem logical that this would be unworkable.

Help greatly appreciated!!

/mawi
 
Back
Top