none
how to get list of data type for database in c#

    Question

  • Hi,

      I am working on the project in which need a conversion of data type of one database to other.

      e.g.

       Data type

        "currency" in access will be mapped to "money" in sql server.

       There are so many such a data types.

       Is there any way to get the list of data types of specified database in c#.

      and can done mapping?

      Thanks in advance....

    Saturday, September 15, 2012 5:02 AM

Answers

  • Hi, 

    You cannot change the DataType of a DataColumn after populating it with data. It's not a read-only property, but you will receive an exception at runtime if you attempt to change it after it already has data.

    If you still want to get the types of the column in side database`s table go check here: 

    http://stackoverflow.com/questions/3417538/need-to-find-the-type-of-the-column-of-db


    Mitja

    Saturday, September 15, 2012 6:46 AM
  • Mitja, hi,

    I think the OP wants to convert a given DataType "on the fly" while writing the data to a DB (of a different DB-Server-Type). So first, maybe look up the types in the www...

    http://msdn.microsoft.com/en-us/library/ms187752.aspx

    http://www.w3schools.com/sql/sql_datatypes.asp

    or search for "Getting table and field names for [your DB-Server-Type]" to get a list of the tables and fields of the current DB and then ge tthe field types from the fields-collection. This may differ a lot on different DB-Types so there's no general script to post here, hust have a look in the www.

    For sql, its something like "SELECT * FROM Information_Schema.Tables WHERE Table_Type = 'BASE TABLE';" to get the tables and "SELECT * FROM Information_Schema.Columns WHERE Table_Name = '" & t & "';" where "t" is the TableName to get the fields...

    Regards,

      Thorsten

    Saturday, September 15, 2012 7:33 AM
  • currency is basically i decimal datatype and you probably can use both float and double without loosing any data, in addition to the currency datatype.

    But why are you going to convert? currency and money columns are normally used in calculations.

    Typical decimal SQL server data type used for currency might be:

    * decimal

    * float

    * money

    * real


    Roar Jørstad Senior consultant http://www.evry.com

    Saturday, September 15, 2012 9:26 AM

All replies

  • Hi, 

    You cannot change the DataType of a DataColumn after populating it with data. It's not a read-only property, but you will receive an exception at runtime if you attempt to change it after it already has data.

    If you still want to get the types of the column in side database`s table go check here: 

    http://stackoverflow.com/questions/3417538/need-to-find-the-type-of-the-column-of-db


    Mitja

    Saturday, September 15, 2012 6:46 AM
  • Mitja, hi,

    I think the OP wants to convert a given DataType "on the fly" while writing the data to a DB (of a different DB-Server-Type). So first, maybe look up the types in the www...

    http://msdn.microsoft.com/en-us/library/ms187752.aspx

    http://www.w3schools.com/sql/sql_datatypes.asp

    or search for "Getting table and field names for [your DB-Server-Type]" to get a list of the tables and fields of the current DB and then ge tthe field types from the fields-collection. This may differ a lot on different DB-Types so there's no general script to post here, hust have a look in the www.

    For sql, its something like "SELECT * FROM Information_Schema.Tables WHERE Table_Type = 'BASE TABLE';" to get the tables and "SELECT * FROM Information_Schema.Columns WHERE Table_Name = '" & t & "';" where "t" is the TableName to get the fields...

    Regards,

      Thorsten

    Saturday, September 15, 2012 7:33 AM
  • currency is basically i decimal datatype and you probably can use both float and double without loosing any data, in addition to the currency datatype.

    But why are you going to convert? currency and money columns are normally used in calculations.

    Typical decimal SQL server data type used for currency might be:

    * decimal

    * float

    * money

    * real


    Roar Jørstad Senior consultant http://www.evry.com

    Saturday, September 15, 2012 9:26 AM