After posting this in .performance newsgroup, I thought it may be more appropriate here. In the following code, when I assigned a ValueType to the Value of a SqlParameter, it gets boxed

System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand("T-SQL HERE", Cn)
Cmd.Parameters.Add("@my_id", SqlDbType.Int)
Cmd.Parameters["@my_id"].Value = prmMyId; //Boxing of integer happens here

Is there any way around this

Re: Simple Q: SqlParameter.Value and Boxing by Erik

Erik
Thu May 13 16:40:03 CDT 2004

"John Smith" <anonymous@discussions.microsoft.com> wrote in message
news:C598A935-A609-4853-8861-176268D9FF42@microsoft.com...
> After posting this in .performance newsgroup, I thought it may be more
appropriate here. In the following code, when I assigned a ValueType to the
Value of a SqlParameter, it gets boxed:
>
> System.Data.SqlClient.SqlCommand Cmd = new
System.Data.SqlClient.SqlCommand("T-SQL HERE", Cn);
> Cmd.Parameters.Add("@my_id", SqlDbType.Int);
> Cmd.Parameters["@my_id"].Value = prmMyId; //Boxing of integer happens
here.
>
> Is there any way around this?

No.

Well, you could implement your own IDBCommands and implement some kind of
strong typing, but it's not worth your time. From a performance
perspective, that boxing is not a very big hit.

Erik



Re: Simple Q: SqlParameter.Value and Boxing by anonymous

anonymous
Thu May 13 17:11:03 CDT 2004

Thanks Erik, that answers my question

If the only boxing I have happen in an entire class is something I can't control, I am happy. :

Cheers!

Re: Simple Q: SqlParameter.Value and Boxing by Pablo

Pablo
Fri May 14 19:15:03 CDT 2004

As Erik pointed out, we currently don't have an API that allows you to avoid
boxing for parameters. I'm curious: do you actually have a specific scenario
where this is needed? We're working on eliminating boxing in many cases in
the next release (whidbey), but we haven't included this one for a number of
reasons. However, if we see that there are specific needs for it, we can
certainly consider it for the next round of designs (post-whidbey).

Thanks,

--
Pablo Castro
Program Manager - ADO.NET Team
Microsoft Corp.

This posting is provided "AS IS" with no warranties, and confers no rights.


"John Smith" <anonymous@discussions.microsoft.com> wrote in message
news:DE5974B2-BB43-43F1-B1D1-80B88AD788FD@microsoft.com...
> Thanks Erik, that answers my question.
>
> If the only boxing I have happen in an entire class is something I can't
control, I am happy. :)
>
> Cheers!