Question about SqlCommand.Parameters.Add() method.

  • Thread starter pedestrian via DotNetMonster.com
  • 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...
 
O

Otis Mukinfus

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
 
P

pedestrian via DotNetMonster.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?

--
Regards,
Pedestrian, Penang.

Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-ado-net/200608/1
 
O

Otis Mukinfus

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 :blush:)
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
W

William \(Bill\) Vaughn

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.
__________________________________
 
P

pedestrian via DotNetMonster.com

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.
 

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