Both of the current answers are slightly incorrect because they're based on the assumption that the constructor being called for your error
object is the (string,object)
one. This is not the case. A literal 0
can be converted to any enum type1, and such a conversion would be preferred over a conversion to object
. So the constructor being called is the (string,SqlDbType)
constructor.
So the type is set to BigInt
because that's the 0
value for the SqlDbType
enumeration, and the Value
is null because you have no code that attempts to set the value.
SqlParameter error = new SqlParameter("@error_code", (object)0);
should cause it to select the correct overload.
Demo:
using System;
using System.Data;
namespace ConsoleApplication
{
internal class Program
{
private static void Main()
{
var a = new ABC("ignore", 0);
var b = new ABC("ignore", (object)0);
var c = new ABC("ignore", 1);
int i = 0;
var d = new ABC("ignore", i);
Console.ReadLine();
}
}
public class ABC
{
public ABC(string ignore, object value)
{
Console.WriteLine("Object");
}
public ABC(string ignore, SqlDbType value)
{
Console.WriteLine("SqlDbType");
}
}
}
Prints:
SqlDbType
Object
Object
Object
1From the C# Language specification, version 5, section 1.10 (that is, just in the introduction to the language, not buried deep down in the language lawyery bits):
In order for the default value of an enum type to be easily available, the literal 0 implicitly converts to any enum type. Thus, the following is permitted.
Color c = 0;
I'd have also thought this important enough to be in the Language Reference on MSDN but haven't found a definitive source yet.