Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:39:56+00:00 2026-06-17T06:39:56+00:00

First, a bit of background. Read the question and accepted answer posted here for

  • 0

First, a bit of background. Read the question and accepted answer posted here for a specific scenario for my question. I’m not sure if other, similar cases exist but this is the only case I am aware of.

The above “quirk” is something that I’ve been aware of for a long time. I didn’t understand the full breadth of the cause until just recently.

Microsoft’s documentation on the SqlParameter class sheds a little more light on the situation.

When you specify an Object in the value parameter, the SqlDbType is
inferred from the Microsoft .NET Framework type of the Object.

Use caution when you use this overload of the SqlParameter constructor
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.

Parameter = new SqlParameter("@pname", Convert.ToInt32(0));

If you do
not perform this conversion, the compiler assumes that you are trying
to call the SqlParameter (string, SqlDbType) constructor overload.

(emph. added)

My question is why does the compiler assume that when you specify a hard coded “0” (and only the value “0”) that you are trying to specify an enumeration type, rather than an integer type? In this case, it assumes that you are declaring SqlDbType value, instead of the value 0.

This is non-intuitive and, to make matters worse, the error is inconsistent. I have old applications that I’ve written which have called stored procedures for years. I’ll make a change to the application (often times not even associated with my SQL Server classes), publish an update, and this issue will all of a sudden break the application.

Why is the compiler confused by the value 0, when an object containing multiple method signatures contain two, similar signatures where one parameter is an object/integer and the other accepts an enumeration?

As I’ve mentioned, I’ve never seen this as a problem with any other constructor or method on any other class. Is this unique to the SqlParameter class or is this a bug inherit within C#/.Net?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:39:57+00:00Added an answer on June 17, 2026 at 6:39 am

    It’s because a zero-integer is implicitly convertible to an enum:

    enum SqlDbType
    {
        Zero = 0,
        One = 1
    }
    
    class TestClass
    {
        public TestClass(string s, object o)
        { System.Console.WriteLine("{0} => TestClass(object)", s); } 
    
        public TestClass(string s, SqlDbType e)
        { System.Console.WriteLine("{0} => TestClass(Enum SqlDbType)", s); }
    }
    
    // This is perfectly valid:
    SqlDbType valid = 0;
    // Whilst this is not:
    SqlDbType ohNoYouDont = 1;
    
    var a1 = new TestClass("0", 0);
    // 0 => TestClass(Enum SqlDbType)
    var a2 = new TestClass("1", 1); 
    // => 1 => TestClass(object)
    

    (Adapted from Visual C# 2008 Breaking Changes – change 12)

    When the compiler performs the overload resolution 0 is an Applicable function member for both the SqlDbType and the object constructors because:

    an implicit conversion (Section 6.1) exists from the type of the argument to the type of the corresponding parameter

    (Both SqlDbType x = 0 and object x = 0 are valid)

    The SqlDbType parameter is better than the object parameter because of the better conversion rules:

    • If T1 and T2 are the same type, neither conversion is better.
      • object and SqlDbType are not the same type
    • If S is T1, C1 is the better conversion.
      • 0 is not an object
    • If S is T2, C2 is the better conversion.
      • 0 is not a SqlDbType
    • If an implicit conversion from T1 to T2 exists, and no implicit conversion from T2 to T1 exists, C1 is the better conversion.
      • No implicit conversion from object to SqlDbType exists
    • If an implicit conversion from T2 to T1 exists, and no implicit conversion from T1 to T2 exists, C2 is the better conversion.
      • An implicit conversion from SqlDbType to object exists, so the SqlDbType is the better conversion

    Note that what exactly constitutes a constant 0 has (quite subtly) changed in Visual C# 2008 (Microsoft’s implementation of the C# spec) as @Eric explains in his answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

( A bit of background can be found in my previous question here, if
first sorry if its a stupid question but im lost a bit. So when
My first post here :) I have a summer job doing a bit of
A bit of background information: Inorder to read/write to SLE4442 memory cards, my app
First a bit of background: I have a WPF application, which is a GUI-front-end
First a little bit of background: I have a REST service in WCF 4
Just a bit of background first. I currently have a site hosted with Windows
Are (seemingly) shady things ever acceptable for practical reasons? First, a bit of background
a bit of background first... I am setting up a versioning numbering system for
First a bit of background: We have a growing RESTful service layer supporting web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.