Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting Meta Data from a DataSet/Table?

Status
Not open for further replies.

VBDotNetProgrammer

Programmer
Jul 9, 2003
50
0
0
GB
Hi,

In Java you can use the "ResultSetMetaData" class to do this. i.e. fetch column widths and types.

Now ive searched everywhere but can't seem to find a vb.net equiv. This is such a handy object i cant believe there isnt a .net equiv.

Does anyone know of it or any other way i can extract base table information from a dataset?

Thanks
 
Use the Dataset Tables property to examine each table.

In the DataTable class there is a collection of DataColumn items called Columns and this can be iterated to examine all the metadata associated with each column.

 
Hi, Thanks for that. I dont suppose you could give me a bit of code to say look at the size of a column in a datatable could you?
 
try something like:
Code:
Dim MyTable as DataTable
Dim MyColumn as DataColumn
for each MyTable in MyDataSet.Tables
    for each MyColumn in MyTable.Columns
        debug.Write MyColumn.ColumnName
        if MyColumn.DataType.ToString() = "String" then
            debug.WriteLine " Length " & MyColumn.MaxLength
        end if
    Next
next
I'm not completely sure about the DataType translation. It may be some other type or there may be several you need to handle. MSDN says that MaxLength is ignored for inappropriate data types so you could just try writing MaxLength anyway.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top