size of a varchar field in SQLserver table

  • Thread starter Thread starter ton
  • Start date Start date
T

ton

Hi,

In ADO I could read the property .DefinedSize of a field of a recordset to
determine the max size of the field. This is very usefull to set the
maxlength property of a textbox. How can this value be determined in the
ADONET- Dataset or datatable.

thanks for a reply


Ton
 
The same interfaces that VS uses to display these properties in the Server
Explorer are available via the GetSchema methods.

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
 
tell me how to do so. I only see a maxlength property of -1
cmd.CommandText = "select top 1 * from " & TableName
myReader = cmd.ExecuteReader(CommandBehavior.KeyInfo)
tbl = myReader.GetSchemaTable()

For Each col In tbl.Columns

' 'Display the field name and length
i = col.MaxLength
MsgBox(i & col.ColumnName )
 
Back
Top