Size of a datacolumn

Is there a way to retrieve the size of a datacolumn? I am looping thru the columns of a table in a dataset in order to retrieve the column name and size. Column name is no problem but I cannot get the size. Anyone?
azrakdragonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gajender_99Commented:
grdtable.TableStyles(0).GridColumnStyles(colnumber).Width = 'Your width'
0
RonaldBiemansCommented:
Hi azrakdragon, Why would you want to know that, all columns except the string have a fixed size.
and the string type doesn't support a fixed size.
0
azrakdragonAuthor Commented:
Looping thru a dataset, not a datagrid.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

azrakdragonAuthor Commented:
I need to determine the length of ech column that is a string type as a flat file is being created with fixed lengths. It needs to be dynamic without a user having to maintain the lengths of each column but having them set using the size of the field in the table.
0
RonaldBiemansCommented:
Well to only way to do this is loop through your datatable and check the lenght of each string in the column

0
azrakdragonAuthor Commented:
It would also come in handy for other things like setting the max length of a text box based on the field it is retrieving its value from etc...
0
azrakdragonAuthor Commented:
Hi RonaldBiemans, If I loop and check the length of each string will the length returned not necessarily be the length defined for the field in the database. i.e. Varchar field of size 50 holds the value "test". The length returned would be 4 instead of 50.
0
RonaldBiemansCommented:
Hi azradragon, I found a way if you add a missingschemaaction to your dataadapter you can use the maxlenght property, like this

OleDbDataAdapter1.MissingSchemaAction = MissingSchemaAction.AddWithKey
        OleDbDataAdapter1.Fill(ds)

        MsgBox(ds.Tables(0).Columns(0).MaxLength)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
azrakdragonAuthor Commented:
Hi RB, many thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.