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

  • Home
  • SEARCH
  • 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 7563133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:35:11+00:00 2026-05-30T13:35:11+00:00

I’m assigning objects to this list of SqlParameter and then trying to execute the

  • 0

I’m assigning objects to this list of SqlParameter and then trying to execute the SqlCommand, but it throws an exception saying that one of the objects could not be converted into SqlDbType. Preferably I want to handle such objects before adding them to the parameter collection list. So, how would I check whether a value being added to parameter list is a good/proper one or not? What property should I check for?

Here’s is my code :

bool Submit(Progs progs, CommandType commandType, string commandText)
{   
    try
    {
        List<SqlParameter> paramCollection = new List<SqlParameter>();
        foreach(Prog p in progs)
        {
            SqlParameter spTemp = new SqlParameter { ParameterName = p.Name , Value = p.Value};
            paramCollection.Add(spTemp);
            using (SqlConnection con = GetConnection())
            {
                SqlCommand cmd = new SqlCommand { CommandType = commandType, CommandText = commandText, Connection = con };  
                con.Open();
                cmd.Parameters.AddRange(paramCollection ); // Exception is thrown from this line
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        catch(Exception exc)
        {
            return false;
        }
    }

The exception thown says :
No mapping exists from object type sol2.CodeBase.BL.Letter[] to a known managed provider native type.

PS : There is a property for of SqlParameter called ParamaterIsSqlType(yes, it’s paramAter and not paramEter), which appears only during runtime(i.e. when I inspect spTemp with a breakpoint on the next line) and which is always set to false? What kind of property is this, so that it appears only during runtime??? Also, what value this “ParamaterIsSqlType” indicates?

  • 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-05-30T13:35:12+00:00Added an answer on May 30, 2026 at 1:35 pm

    Do what SqlParameter would do to infer conversion from Type to SqlDbType if it’s not set explicitely. So, no, there’s (yet) no property or method available in the framework.

    System.Type type = p.Value.GetType();
    var isConvertible = IsConvertibleToSqlDbType(type);
    if(!isConvertible){
        //call your custom ToSqlType-method
    }
    

    Following method is derived directly from SqlParemeter's private void InferSqlType (object value):

    public static bool IsConvertibleToSqlDbType(Type type)
    {
        switch(type.FullName) {
            case "System.Int64":
            case "System.Data.SqlTypes.SqlInt64":
                //SetSqlDbType (SqlDbType.BigInt);
                return true;
            case "System.Boolean":
            case "System.Data.SqlTypes.SqlBoolean":
                //SetSqlDbType (SqlDbType.Bit);
                return true;
            case "System.String":
            case "System.Data.SqlTypes.SqlString":
                //SetSqlDbType (SqlDbType.NVarChar);
                return true;
            case "System.DateTime":
            case "System.Data.SqlTypes.SqlDateTime":
                //SetSqlDbType (SqlDbType.DateTime);
                return true;
            case "System.Decimal":
            case "System.Data.SqlTypes.SqlDecimal":
                //SetSqlDbType (SqlDbType.Decimal);
                return true;
            case "System.Double":
            case "System.Data.SqlTypes.SqlDouble":
                //SetSqlDbType (SqlDbType.Float);
                return true;
            case "System.Byte[]":
            case "System.Data.SqlTypes.SqlBinary":
                //SetSqlDbType (SqlDbType.VarBinary);
                return true;
            case "System.Byte":
            case "System.Data.SqlTypes.SqlByte":
                //SetSqlDbType (SqlDbType.TinyInt);
                return true;
            case "System.Int32":
            case "System.Data.SqlTypes.SqlInt32":
                //SetSqlDbType (SqlDbType.Int);
                return true;
            case "System.Single":
            case "System.Data.SqlTypes.Single":
                //SetSqlDbType (SqlDbType.Real);
                return true;
            case "System.Int16":
            case "System.Data.SqlTypes.SqlInt16":
                //SetSqlDbType (SqlDbType.SmallInt);
                return true;
            case "System.Guid":
            case "System.Data.SqlTypes.SqlGuid":
                //SetSqlDbType (SqlDbType.UniqueIdentifier);
                return true;
            case "System.Money":
            case "System.SmallMoney":
            case "System.Data.SqlTypes.SqlMoney":
                //SetSqlDbType (SqlDbType.Money);
                return true;
            case "System.Object":
                //SetSqlDbType (SqlDbType.Variant); 
                return true;
            default:
                return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.