Groups | Blog | Home
all groups > dotnet ado.net > march 2008 >

dotnet ado.net : size of a varchar field in SQLserver table



ton
3/19/2008 9:41:21 PM
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
William Vaughn
3/21/2008 11:18:31 AM
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)
____________________________________________________________________________________________
[quoted text, click to view]
ton
3/25/2008 1:08:16 PM
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 )


"William Vaughn" <billvaNoSPAM@betav.com> schreef in bericht
news:7E309E57-328F-43A0-BC39-69D2DA0A8FF1@microsoft.com...
[quoted text, click to view]
RobinS
3/27/2008 5:00:54 PM
[quoted text, click to view]

Just FYI, most people don't take kindly to commands.

Try ColumnSize.

RobinS.


[quoted text, click to view]
AddThis Social Bookmark Button