30-11-21 09:31 AM
Answered! Go to Answer.
07-12-21 11:28 PM
Output_Collection.ImportRow(row)
and instead we are using a different looping logic altogether so that we can check the date data type and accordingly convert just that one column value to Local format instead of importing all the rows at once.For Each column As System.Data.DataColumn In Input_Collection.Columns
If Field_Name.Equals(column.ColumnName) Then
If CStr(Field_Type).ToUpper.Equals("TEXT") Then
Output_Collection.Columns.Add(column.ColumnName,GetType(String))
ElseIf CStr(Field_Type).ToUpper.Equals("NUMBER") Then
Output_Collection.Columns.Add(column.ColumnName,GetType(Integer))
ElseIf CStr(Field_Type).ToUpper.Equals("FLAG") Then
Output_Collection.Columns.Add(column.ColumnName,GetType(Boolean))
ElseIf CStr(Field_Type).ToUpper.Equals("DATE") Then
Output_Collection.Columns.Add(column.ColumnName,GetType(Date))
Else
Throw New Exception("Invalid File Type Provided")
End If
Else
Output_Collection.Columns.Add(column.ColumnName,column.DataType)
End If
Next
Dim newRow As System.Data.DataRow
For Each row as System.Data.DataRow In Input_Collection.Rows
newRow = Output_Collection.NewRow()
For Each column as System.Data.DataColumn In Output_Collection.Columns
If column.DataType = GetType(Date) Then
newRow(column.ColumnName) = CDate(row(column.ColumnName)) + New TimeSpan(0,Time_Difference_In_Hours,Time_Difference_In_Minutes,Time_Difference_In_Seconds)
Else
newRow(column.ColumnName) = row(column.ColumnName)
End If
Next
Output_Collection.Rows.Add(newRow)
Next
Test Results:08-12-21 04:30 PM
08-12-21 04:57 PM
08-12-21 08:12 PM
08-12-21 08:32 PM
Once we created using external data, systematically numeric columns are taken to as data type objects instead of int or float, creating numeric tasks not possible. We will pass any Python, Numpy, or Pandas datatype to vary all columns of a dataframe thereto type, or we will pass a dictionary having column names as keys and datatype as values to vary the type of picked columns.
Here function empowers us to be express the data type you need to have. It's extremely adaptable i.e you can attempt to go from one type to some other.
Attention geek! Strengthen your foundations with the Course and learn the basics.
07-08-24 03:24 PM
Hi Vinod.
I'm curious as to how you used a loop and calc stage to change the Data Type of your column. I need to do this myself. It could be any column that needs to be changed and it could be a different column every time.
Any help would be appreciated.
Thanks
JB
12-08-24 03:44 PM
Hi Devneet,
I've tried using your code below to update a data type in my collection but I'm getting the error below:
Description: Compiler error at line 20: 'Output_Collection' is not declared. It may be inaccessible due to its protection level.
Any suggestions and how I can correct this please?