Results 1 to 4 of 4

Thread: [RESOLVED] Datatable select ordering

  1. #1

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Resolved [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

  2. #2

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    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.

  3. #3

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    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

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width