Simple Q: SqlParameter.Value and Boxing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
John Smith said:
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
 
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!
 
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.
 
Back
Top