[RESOLVED] Datatable select ordering
Hi, I have a dataset generated from xml from a web service.
Data needs to be sorted by date order descending, I cannot get the web service changed so thought I'd try:
Code:
repeater1.DataSource = dsCombinedBlock.Tables(2).Select("Status < 3 and status <> 99", "DateReceived desc")
However the dates are treated as a string so the results look like
28/06/2011
27/06/2011
27/06/2011
02/06/2011
01/07/2011
How do I get the proper ordering applied.
thanks Dave
Re: Datatable select ordering
I thought perhaps the column had to be a type of date, then i ran into other problem
when trying to change the column type and import the data
Code:
If table1Success = True Then
'// Table1
UPRNjobs = UPRNjobs_C1.Clone
UPRNjobs.Tables(2).Columns("DateReceived").DataType = GetType(Date)
For Each dr As DataRow In UPRNjobs_C1.Tables(2).Rows
UPRNjobs.Tables(2).ImportRow(dr)
Next
If table2success = True Then
'// Combine both tables
For Each dr As DataRow In UPRNjobs_C2.Tables(2).Rows
UPRNjobs.Tables(2).ImportRow(dr)
Next
End If
Else
If table2success = True Then
'// Table 2 only
UPRNjobs = UPRNjobs_C2.Clone
UPRNjobs.Tables(2).Columns("DateReceived").DataType = GetType(Date)
For Each dr As DataRow In UPRNjobs_C2.Tables(2).Rows
UPRNjobs.Tables(2).ImportRow(dr)
Next
End If
End If
I get this message
ForeignKeyConstraint Data_Row requires the child key values (0) to exist in the parent table.
Re: Datatable select ordering
not sure what the problem was, but i set enforeConstraints to false, and it works now. Doesn't seem like best solution but hey ho
Re: [RESOLVED] Datatable select ordering
Hello,
I would have to agree.
The best solution would be to get the Web Service to be able to return the data in the format required. You mentioned that there was no way to change the Web Service, is this a hard and fast decision?
Gary