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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp.net field length

Status
Not open for further replies.

marcusmco

IS-IT--Management
Oct 9, 2006
30
AU
Hello,

I have a dataset that was loaded from the database and I am interested in finding the varchar length of a certain field. Is that possible using the dataset? I have tried to use the GetType function but I cannot find the length of the varchar field...

Regards,
Marcus
 
Try the following:
Code:
  'Length on a String type field:
  DataSet.Tables("TName").Rows(1).Item("Text").Length
Item returns an Object that can be anything, so you have GetType to check what type it is. But because you know that its a String, you can access is properties and functions without even seeing them (as in the example above). You could set it to a String, if that helps:
Code:
  Dim Str As String
  Str = DataSet.Tables("TName").Rows(1).Item("Text").Length
 
Sorry I was not being clear about what I wanted.

I was looking for the maximum length of the field. It is a varchar field and I would like to be able to find what is within the brackets when defining the field. E.g. if it in the database says varchar(50) I would like to be able to get 50 back.
 
I did write that first, then deleted it and put the value length.
Code:
Datarow.Tables("TName").Columns("Text").MaxLength()

Hope this one helps
 
Sorry again, I should read posts better.

How are you connecting to the database? And which database are you using (sql server)?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top