Go4Expert

Go4Expert (http://www.go4expert.com/)
-   ASP (http://www.go4expert.com/forums/asp/)
-   -   how to know explicitly the data type of a field in a database (http://www.go4expert.com/forums/explicitly-data-type-field-database-t20217/)

shyam_oec 27Nov2009 21:16

how to know explicitly the data type of a field in a database
 
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?

urstop 8Dec2009 04:45

Re: how to know explicitly the data type of a field in a database
 
Which field in the table you would like to compare it against, as a table can have more than one columns?

shyam_oec 8Dec2009 08:12

Re: how to know explicitly the data type of a field in a database
 
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?

venami 8Dec2009 08:32

Re: how to know explicitly the data type of a field in a database
 
You can get the details from the metadata tables of your DBMS. What is the DBMS that you use?

urstop 8Dec2009 14:54

Re: how to know explicitly the data type of a field in a database
 
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.


All times are GMT +5.5. The time now is 22:39.