[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 954
  • Last Modified:

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?
0
azrakdragon
Asked:
azrakdragon
  • 5
  • 3
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
azrakdragonAuthor Commented:
Hi RB, many thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now