Link to home
Start Free TrialLog in
Avatar of Mr_Shaw
Mr_Shaw

asked on

.MaxLength.ToString();

when I write

 row["Data_Length"] = col.MaxLength.ToString();

it return I get a value of -1.

what does -1 indicate?
SOLUTION
Avatar of mkobrin
mkobrin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Shaw
Mr_Shaw

ASKER

What is false about:

 row["Data_Length"] = col.MaxLength.ToString();

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Shaw

ASKER

How can I get the length of the data type in a column?
The length of the column or the length of the data in the current row?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Brad Brett
Brad Brett
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Shaw

ASKER

How do I find out the lenght of the data type in the columns?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can determine a datatype at runtime using the following code:
For Each col As DataColumn In MyDatatable.Columns
    If col.DataType Is GetType(String) Then
        MsgBox(col.ColumnName & " is a string")
    End If
    If col.DataType Is GetType(Integer) Then
        MsgBox(col.ColumnName & " is an integer")
    End If
    ' etc...
Next

Open in new window

Avatar of Mr_Shaw

ASKER

Medo3337... how about getting the length?

eg. the string length
Here is SQL to get the field length:
SELECT 
sysobjects.name AS "TABLE_NAME", 
syscolumns.name AS "COLUMN_NAME", 
systypes.name AS "DATA_TYPE", 
syscolumns.LENGTH AS "LENGTH" 
FROM
         	sysobjects
INNER JOIN
 		syscolumns ON sysobjects.id = syscolumns.id 
INNER JOIN
		systypes ON syscolumns.xtype = systypes.xtype 
WHERE
(sysobjects.xtype = 'U') andsysobjects.name = 'MyTableName' 
ORDER BY sysobjects.name, syscolumns.colid

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Shaw

ASKER

thanks