MaxLength limit of this column using Linq

Hi Team,

While adding the data to clone datatable using below code.
i getting on error. can tell how to add max length as -1 in the linq

Code :

(From r In Out_Dt.AsEnumerable()
Let va = r.ItemArray
Select Dt_New.Rows.Add(va)).CopyToDataTable

Error:
Assign: Cannot set column ‘Col1’. The value violates the MaxLength limit of this column.

Thanks
Shyam

Hi Shyam ,

It appears that you are trying to copy the contents of a DataTable (Out_Dt) to another DataTable (Dt_New). However, you are encountering an error because one of the values from the Out_Dt exceeds the MaxLength property of the corresponding column in Dt_New.
Assign Dt_New.columns(“col1”).maxlength=-1
To resolve this issue, you should make sure that the MaxLength property of the columns in Dt_New are either set to -1 (which means no limit) or set to a value that is equal to or greater than the maximum length of the corresponding columns in Out_Dt.

Happy Automation

You could reconfigure Dt_New Columns before usage

@Shyam_Pragash

try this

before the query use this

assign activity

Dt_New.columns(“col1”).maxlength=-1

cheers

Hi @ppr @Shiva_Nikhil @AutomationX_by_Kiran

First : Get the data from sql server (using Query) stored Out_Dt
Second : Convert the all the columns datatype into System.Object in for each activity.
Thrid : After converted All columns datatype to object… try add values from (Out_Dt) while adding the values i got error in Col1 MaxLenth Limit of this Columns.

Error:
image

Code:

Thanks
Shyam

HI,

We cannot change datatype of Column if data exists in the column.
The above workflow doesn’t change data type of columns of Out_Dt because ForEach iterates Out_Dt.Clone

For now, can you try to add Dt_Out.Columns("RQ_VALUE").MaxLength = -1 just before the Assign of the LINQ?

image

Regards,

Hi @Yoichi

I have 126 Columns cant able mention individual columns Name one by one. so that can i use one more for each activity to iterate the all the columns max length as -1

Thanks
Shyam

Hi,

How about the following?

It may not be necessary If activity. (To make sure, the above sample change max length in only string type)

Regards,