How to know length (data width) of column from VB.Net

  • Thread starter Thread starter Hardik Shah
  • Start date Start date
H

Hardik Shah

Hi,

I have a table in SQL Server 2000 and accessing it in ADO.Net , I want to
know fields width and I gave following VB.Net commands but I am fail to know
it, it returns -1 for all columns.

Dim col as data.datacolumn

For Each col in ds.tables(0).columns ' ds is a dataset
Console.Writeline (col.maxlength)
Next

Thanks in advance.

Hardik Shah.
 
Hi there,

1. (preffered) Use sp_columns stored procedure to obtain full complete
column description
2. MaxLen works fine for text/binary columns, for other (value) types you
have to use DataType and System.Runtime.InteropServices.Marshal.SizeOf but
you will get .net underlying type information

Hope this helps
 
Back
Top