how to know explicitly the data type of a field in a database

Discussion in 'ASP' started by shyam_oec, Nov 27, 2009.

  1. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    hi all,
    i am creating a method that accepts a String parameter ,a SqlConnection type paremeter and a String parameter for storing the name of table,like this

    public int validation(String str,SqlConnection sqlcon,String table_name)
    {
    ...
    ...
    }

    This method is created in a ClassLibrary file,that i will use it in my main project.From main project this validation() method will be called to check whether the string 'str' passed is of specified type as in the database table's particular field.
    So,how to get the datatype of a field of a particular table in a particular database?
     
  2. urstop

    urstop New Member

    Joined:
    Oct 17, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Which field in the table you would like to compare it against, as a table can have more than one columns?
     
  3. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    hi,
    In my own defined method ,i will pass the connection string of the database and table name in the parameter.
    And my method should return the number of columns and datatype of each column in the table.
    That how to do?
     
  4. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    You can get the details from the metadata tables of your DBMS. What is the DBMS that you use?
     
  5. urstop

    urstop New Member

    Joined:
    Oct 17, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    You can execute the stored procedure sp_help with the tablename to get a resultset with the column names, data type and other extra info. You can use this resultset to extract the necessary colulmn name and data type information.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice