Re: SqlParameter of a SqlType

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

I would not expect that Guid type should allow to accept NULL values. What
you could do is to set it to Nothing in a case if output parameter is NULL.
In this case you will keep result in one variable, but in a case of NULL it
will be set to Nothing

--
Val Mazur
Microsoft MVP

http://xport.mvps.org



"Aleksei" <aleksei.guzev@xxxxxxxxx> wrote in message
news:1113995160.707798.184240@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> SqlParameter converts the value to a CLR type. But this is a problem
> while storing OUTPUT parameter values to CLR variable of a type from
> System.Data.SqlTypes namespace. For example, the following obviously
> does not work
>
> SqlParameter p = new SqlParameter ("@id",SqlDbType.UniqueIdentifier);
> SqlGuid id = (SqlGuid) p.Value;
>
> Replacing the second line helps
>
> SqlGuid id;
> if (p.Value is DBNull) id=SqlGuid.Null;
> else id.Value=(Guid) p.Value;
>
> But this solution implies two conversions and the performance gain
> (noted in MSDN library, "System.Data.SqlTypes") could not be achieved.
>
> Using CLR type System.Guid instead of System.Data.SqlTypes.SqlGuid
> denies accepting DBNull values.
>
> Is there any way to get SqlType from a SqlParameter directly? Maybe I
> have missed something?
>
> Aleksei
>


.