I have a DataTable that I have populated via the Dataset.ReadXML() method. I am trying to programatically determine the maximum field lengths for each column in the datatable. The MaxLength value for all of my columns is always at the default of -1.
Any thoughts or examples on how to determine the proper max length? maybe based on the actual data in the table? (Datatable can be in the 25 column by 200,000+ row range)
C# 2.0
I don't quite understand what your objectives are - what are you trying to find out? The number of bytes a given column will use (e.g. 4 for INT, 8 for BIGINT and so forth), or the actual current maximum length of e.g. all strings in column "ColA" ?
As for the INT and other numerical and boolean types - those have a fixed system-given length - no problems there.
Unless your XML has a schema (XSD file) which limits the string lengths, the string fields from an XML can be any length, really, so after reading them in, your DataTable can't really know what the defined max length can be.
All you can do is loop over all rows in your DataTable and determine the current length of the strings, and get the maximum of those current lengths, as your frame of reference.
Does that help at all?
Marc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With