Home All Groups Group Topic Archive Search About

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

Author
14 Feb 2006 5:48 AM
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.

Author
14 Feb 2006 8:58 AM
Milosz Skalecki
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
--
Milosz Skalecki
MCP, MCAD


Show quote
"Hardik Shah" wrote:

> 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.
>
>
>
>
>

AddThis Social Bookmark Button