Problem with SqlParameterCollection.Add(String parameterName, Object value)

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

Guest

Hi

I have a web app which is running a report, when I change a parameter under a certain circumstance I get the error message below, I cannot logically work out what is happening, it seems to be falling over outside of my code. If anyone has any information or pointers I would greatly appreciate your help, see error stack belo

Message: The parameter data type of UInt32 is invalid
Source: System.Dat
TargetSite: System.Data.SqlClient.MetaType GetMetaType(System.Object
ErrorType: System.ArgumentExceptio
Parameter: '' was invalid
StackTrace:
 
What does the parameter declaration look like?
Neil said:
Hi,

I have a web app which is running a report, when I change a parameter
under a certain circumstance I get the error message below, I cannot
logically work out what is happening, it seems to be falling over outside of
my code. If anyone has any information or pointers I would greatly
appreciate your help, see error stack below
Message: The parameter data type of UInt32 is invalid.
Source: System.Data
TargetSite: System.Data.SqlClient.MetaType GetMetaType(System.Object)
ErrorType: System.ArgumentException
Parameter: '' was invalid.
StackTrace:

-------------------------------------------------------------------------- ------
at System.Data.SqlClient.MetaType.GetMetaType(Object value)

-------------------------------------------------------------------------- ------
at System.Data.SqlClient.SqlParameter.SetTypeInfoFromComType(Object value)

-------------------------------------------------------------------------- ------
at System.Data.SqlClient.SqlParameter.set_Value(Object value)

-------------------------------------------------------------------------- ------
at System.Data.SqlClient.SqlParameter..ctor(String parameterName, Object value)
Object value)
 
Hi Neil,

Can be this the problem?
"Use caution when using this overload of the Add method to specify integer
parameter values. Because this overload takes a value of type Object, you
must convert the integral value to an Object type when the value is zero, as
the following C# example demonstrates.
parameters.Add("@pname", Convert.ToInt32(0));
If you do not perform this conversion, the compiler will assume you are
attempting to call the SqlParameterCollection.Add (string, SqlDbType)
overload."

(from help file)

What is your code, anyway?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Neil said:
Hi,

I have a web app which is running a report, when I change a parameter
under a certain circumstance I get the error message below, I cannot
logically work out what is happening, it seems to be falling over outside of
my code. If anyone has any information or pointers I would greatly
appreciate your help, see error stack below
Message: The parameter data type of UInt32 is invalid.
Source: System.Data
TargetSite: System.Data.SqlClient.MetaType GetMetaType(System.Object)
ErrorType: System.ArgumentException
Parameter: '' was invalid.
StackTrace:

-------------------------------------------------------------------------- ------
at System.Data.SqlClient.MetaType.GetMetaType(Object value)

-------------------------------------------------------------------------- ------
at System.Data.SqlClient.SqlParameter.SetTypeInfoFromComType(Object value)

-------------------------------------------------------------------------- ------
at System.Data.SqlClient.SqlParameter.set_Value(Object value)

-------------------------------------------------------------------------- ------
at System.Data.SqlClient.SqlParameter..ctor(String parameterName, Object value)
Object value)
 
object oValue = dicParameters[ strKey ]

SqlParameter param = parameters.Add( strKey, oValue );
 
Yeh I read that too but I don't think that is the problem, see my declaration belo

object oValue = dicParameters[ strKey ]
SqlParameter param = parameters.Add( strKey, oValue )

Do you agree?
 
What is the type of oValue? (oValue.GetType())
It might be a UInt32 :) which is probably not supported.
Try parameters.Add( strKey, Convert.ToInt32(oValue));
 
What is the value of the param... if it's zero, this is the likely problem
http://www.knowdotnet.com/articles/parametergotcha.html

To know for sure, change it to
SqlParameter param = parameters.Add( strKey );
cmd.Parameters[strKey].Value = oValue;

If it's not the problem, then no big deal but if this fixes it, it pretty
much nails it down.

William Ryan eMVP said:
What does the parameter declaration look like?

under a certain circumstance I get the error message below, I cannot
logically work out what is happening, it seems to be falling over outside of
my code. If anyone has any information or pointers I would greatly
appreciate your help, see error stack below
parameterName,
Object value)
[/QUOTE]
 
Back
Top