Simple Q: SqlParameter.Value and Boxing

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
 
E

Erik Frey

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
 
G

Guest

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!
 
P

Pablo Castro [MS]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top