none
Retrieving Columns Information for SQL Server Table RRS feed

  • Question

  •  

    In my app, i need to get columns information from a sql table.

    Im using

     

    DataTableReader^ reader = gcnew DataTableReader( DataTable );

    schemaTable = reader->GetSchemaTable();

     

    This give me most of infos i need, but i cannot retrieve the Expression field. Its allways DBNull.

     

    Do you know a way to retrieve Expression information?

    ( Computed Column Specification->Formula in SQL Management Studio )

     

    Im using Visual C++ 2005 Express.

    Thursday, March 13, 2008 10:55 AM

Answers

  • The Expression property of the DataColumn object doesn't come from the database; it's purely part of the ADO in-memory representation of your data set.  It has its own syntax and its own capabilities that are distinct from SQL Server's (or any other database that ADO might interoperate with).  It's always going to be DBNull unless you set it yourself when you create the DataColumn object, e.g.:

     

    Code Snippet

    DataColumn amount = new DataColumn("Amount", typeof(System.Decimal));

    amount.Expression = "Quantity * Price";

    table.Columns.Add(amount);

     

     

    Monday, March 17, 2008 7:40 PM

All replies

  • hi,

    moving thread to ADO.Net forum.. perhaps here better answers will come..

    looking around I only found the .GetSchema method does not seems to return enougth info about your requirements..

    you probably have to directly query metadata views of the database..

    regards

    Friday, March 14, 2008 11:54 PM
  • The Expression property of the DataColumn object doesn't come from the database; it's purely part of the ADO in-memory representation of your data set.  It has its own syntax and its own capabilities that are distinct from SQL Server's (or any other database that ADO might interoperate with).  It's always going to be DBNull unless you set it yourself when you create the DataColumn object, e.g.:

     

    Code Snippet

    DataColumn amount = new DataColumn("Amount", typeof(System.Decimal));

    amount.Expression = "Quantity * Price";

    table.Columns.Add(amount);

     

     

    Monday, March 17, 2008 7:40 PM