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 6026293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:25:28+00:00 2026-05-23T04:25:28+00:00

So, I have the following: SELECT * FROM MyTable; When I do the following

  • 0

So, I have the following: "SELECT * FROM MyTable;"

When I do the following I get the TableData back, which is useful, but still leaves some things unknown?

//CommandBehavior.KeyInfo seems to actually return the correct primary keys
// not so much with CommandBehavior.SchemaOnly.
IDataReader reader = command.ExecuteReader(CommandBehavior.KeyInfo)

DataTable table = reader.GetSchemaTable();

now, when iterating over my table I come across a column named “DataType” and it is either System.String or System.Byte[] or System.Int32, etc. But, this only tells me the .NET type to store, it doesn’t tell me if, for example, a System.Decimal is the DbType.Currency or DbType.Decimal. So when I’m creating an IDataParameter, I’m not sure what to set for the DbType.

parameter.ColumnName = columnName;
parameter.DbType = DbType.Decimal; (or should it have been Currency?)

Basically, how can I get the table’s real schema… or does it even matter?

  • 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-23T04:25:29+00:00Added an answer on May 23, 2026 at 4:25 am

    If you are passing in parameters for a stored procedure, or some sql text, no you do not need to specify the parameters data type. the SqlCommand will correctly assign the data type for you.

    I believe the ability to assign the DBType on a parameter is if you want to overwrite what the system would choose for you.

    use the

    SqlCommand.Parameters.AddWithValue("@parameterName", valueAsObject);
    

    command

    edit you are using the IDbCommand, not the SqlCommand. I know that both SqlCommand and Oracle command do not need you to specify the DbType, but I do not know if other frameworks do need you to explicitly set the DbType. here is a method to tranform a system.type to a DbType enum value:

    Class DBTypeConversion
    {
        private static String[,] DBTypeConversionKey = new String[,] 
        {
         {"BigInt","System.Int64"},
         {"Binary","System.Byte[]"},
         {"Bit","System.Boolean"},
         {"Char","System.String"},
         {"DateTime","System.DateTime"},
         {"Decimal","System.Decimal"},
         {"Float","System.Double"},
         {"Image","System.Byte[]"},
         {"Int","System.Int32"},
         {"Money","System.Decimal"},
         {"NChar","System.String"},
         {"NText","System.String"},
         {"NVarChar","System.String"},
         {"Real","System.Single"},
         {"SmallDateTime","System.DateTime"},
         {"SmallInt","System.Int16"},
         {"SmallMoney","System.Decimal"},
         {"Text","System.String"},
         {"Timestamp","System.DateTime"},
         {"TinyInt","System.Byte"},
         {"UniqueIdentifer","System.Guid"},
         {"VarBinary","System.Byte[]"},
         {"VarChar","System.String"},
         {"Variant","System.Object"}
        };
    
    
        public static SqlDbType SystemTypeToDbType( System.Type sourceType )
        {
        SqlDbType result;
        String SystemType = sourceType.ToString();
        String DBType = String.Empty;
        int keyCount = DBTypeConversionKey.GetLength(0);
    
        for(int i=0;i<keyCount;i++)
        {
        if(DBTypeConversionKey[i,1].Equals(SystemType)) DBType = DBTypeConversionKey[i,0];
        }
    
        if (DBType==String.Empty) DBType = "Variant";
    
        result = (SqlDbType)Enum.Parse(typeof(SqlDbType), DBType);
    
        return result;
        }
    
        public static Type DbTypeToSystemType( SqlDbType sourceType )
        {
        Type result;
        String SystemType = String.Empty;
        String DBType = sourceType.ToString();
        int keyCount = DBTypeConversionKey.GetLength(0);
    
        for(int i=0;i<keyCount;i++)
        {
        if(DBTypeConversionKey[i,0].Equals(DBType)) SystemType = DBTypeConversionKey[i,1];
        }
    
        if (SystemType==String.Empty) SystemType = "System.Object";
    
        result = Type.GetType(SystemType);
    
        return result;
        }
    

    http://social.msdn.microsoft.com/Forums/en/winforms/thread/c6f3ab91-2198-402a-9a18-66ce442333a6
    hope this helps better clarify.

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx

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

Sidebar

Related Questions

I have the following statement SELECT id, descr from mytable which returns 1, 'Test1'
I have the following query: SELECT M.Col7, M.Col8, M.Col9, M.Col10 FROM [MyTable] M WHERE
I have a problem with the following HQL query: select sum(MYTABLE.COUNTER) from ( select
I have the following query: SELECT c.* FROM companies AS c JOIN users AS
I have the following SQL-statement: SELECT DISTINCT name FROM log WHERE NOT name =
I have tried the following two statements: SELECT col FROM db.tbl WHERE col (LIKE
I have the following query: select column_name, count(column_name) from table group by column_name having
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
I have the following string expression in a PowerShell script: select count(*) cnt from
I have the following (shortened query): SELECT `Statistics`.`StatisticID`, COUNT(DISTINCT `Flags`.`FlagType`) AS `FlagCount` FROM `Statistics`

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.