Solved

.MaxLength.ToString();

Posted on 2011-03-14
14
347 Views
Last Modified: 2013-12-17
when I write

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

it return I get a value of -1.

what does -1 indicate?
0
Comment
Question by:Mr_Shaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +2
14 Comments
 
LVL 7

Assisted Solution

by:mkobrin
mkobrin earned 84 total points
ID: 35129478
it indicates that your statemant is false. What are you trying to do?
0
 

Author Comment

by:Mr_Shaw
ID: 35129528
What is false about:

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

0
 
LVL 10

Assisted Solution

by:Nash2334
Nash2334 earned 313 total points
ID: 35129534
-1 indicates that no MaxLength is specified.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:Mr_Shaw
ID: 35129543
How can I get the length of the data type in a column?
0
 
LVL 10

Expert Comment

by:Nash2334
ID: 35129584
The length of the column or the length of the data in the current row?
0
 
LVL 10

Assisted Solution

by:Nash2334
Nash2334 earned 313 total points
ID: 35129594
MaxLength only applies to text columns.  Other columns are limited by their data types.
0
 
LVL 12

Assisted Solution

by:Mohamed Abowarda
Mohamed Abowarda earned 83 total points
ID: 35129630
Check the variable "col", make sure it's associated with a column.
0
 

Author Comment

by:Mr_Shaw
ID: 35129646
How do I find out the lenght of the data type in the columns?
0
 
LVL 9

Assisted Solution

by:gery128
gery128 earned 20 total points
ID: 35129648
Col is a TextBox ? have you set the MaxLength property ?
0
 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35129687
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
 

Author Comment

by:Mr_Shaw
ID: 35129762
Medo3337... how about getting the length?

eg. the string length
0
 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35129839
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
 
LVL 10

Accepted Solution

by:
Nash2334 earned 313 total points
ID: 35129853
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
 

Author Closing Comment

by:Mr_Shaw
ID: 35129967
thanks
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question