How do I get the SqlDbType of a column in a table using ADO.NET?

前端 未结 5 2004
野性不改
野性不改 2020-12-31 21:45

I\'m trying to determine at runtime what the SqlDbType of a sql server table column is.

is there a class that can do that in System.Data.SqlClient or should I do the

5条回答
  •  庸人自扰
    2020-12-31 22:02

    For SQL Server, use the SMO (SQL Server Management Objects).

    http://www.yukonxml.com/articles/smo/

    For example, you can use this code to traverse over all of the columns of a table.

    Server server = new Server();
    Database database = new Database( "MyDB" );
    Table table = new Table( database, "MyTable" );
    
    foreach ( Column column in table.Columns )
    {
            WriteLine( column.Name ); 
    }   
    

    Here are all of the column properties available to you: http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.column_members.aspx

提交回复
热议问题