Question about SqlCommand.Parameters.Add() method.

  • Thread starter Thread starter pedestrian via DotNetMonster.com
  • Start date Start date
P

pedestrian via DotNetMonster.com

I'm currently programming an ADO.NET application for SQL server.
I notice that the SqlCommand.Paraterers.Add() method require 4 parameters
which are parameterName, SqlDbType, Size, and SourceCOlumn. The question is
with Size parameter:

What is the corrent Size value for SqlDbType.Int, SqlDbType.Money and
SqlDbType.Real? I'm adding those type to the method.

Thanks...
 
I'm currently programming an ADO.NET application for SQL server.
I notice that the SqlCommand.Paraterers.Add() method require 4 parameters
which are parameterName, SqlDbType, Size, and SourceCOlumn. The question is
with Size parameter:

What is the corrent Size value for SqlDbType.Int, SqlDbType.Money and
SqlDbType.Real? I'm adding those type to the method.

Thanks...

If you use this overloaded method the length will be provided:

public SqlParameter Add (string parameterName,
SqlDbType sqlDbType)

or you can use the AddWithValue method:

public SqlParameter AddWithValue (string parameterName,
Object value)

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
Thanks for replying, Otis.

I'm using the 4 parameters overload method because I like to specify the
SourceColumn (in Sql server).
I found that Sp_help in Sql Server give the length of the type, is the length
the answer to the Size value in SqlParameter.Add method?

Yes. Please excuse my poor choice of words :o)
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
When the overloads don't have the right mix of property settings we have to
resort to multiple property set operations. You might just try setting the
length to the size of the Integer as stated in the help or 0. I expect it's
ignored anyway.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Thanks Otis. All to best to you...

Thanks William. I guess you are right. I did set the Size to 8 for SqlDbType.
Int unintentionally and
it don't show me the error...

Have a nice days, guys.
 
Back
Top