• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

.MaxLength.ToString();

when I write

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

it return I get a value of -1.

what does -1 indicate?
0
Mr_Shaw
Asked:
Mr_Shaw
  • 5
  • 4
  • 3
  • +2
6 Solutions
 
mkobrinCommented:
it indicates that your statemant is false. What are you trying to do?
0
 
Mr_ShawAuthor Commented:
What is false about:

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

0
 
Nash2334Commented:
-1 indicates that no MaxLength is specified.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Mr_ShawAuthor Commented:
How can I get the length of the data type in a column?
0
 
Nash2334Commented:
The length of the column or the length of the data in the current row?
0
 
Nash2334Commented:
MaxLength only applies to text columns.  Other columns are limited by their data types.
0
 
Mohamed AbowardaSoftware EngineerCommented:
Check the variable "col", make sure it's associated with a column.
0
 
Mr_ShawAuthor Commented:
How do I find out the lenght of the data type in the columns?
0
 
gery128Commented:
Col is a TextBox ? have you set the MaxLength property ?
0
 
Mohamed AbowardaSoftware EngineerCommented:
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

0
 
Mr_ShawAuthor Commented:
Medo3337... how about getting the length?

eg. the string length
0
 
Mohamed AbowardaSoftware EngineerCommented:
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

0
 
Nash2334Commented:
If you want the length of a string in a DataColumn that is of type string for a specific DataRow, you need to access the row and column specifically:

myDataRow[0][0].ToString().Length

Will give you the length of the data in cell 0 of row 0.  If it's nullable you should do a null check first.
0
 
Mr_ShawAuthor Commented:
thanks
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now