views:

356

answers:

1

I populate a DataTable, then sort the DefaultView of that DataTable. When I set the DataTable as the source for my report, the sort doesn't work. In case it helps, here is the code (GetData returns a valid DataTable):

    Dim dt As DataTable = a.GetData(Parm1, Parm2, Parm3)

    If rbtSortByField1.Checked Then
        dt.DefaultView.Sort = "Field1 ASC"
    ElseIf rbtSortByField2.Checked Then
        dt.DefaultView.Sort = "Field2 ASC"
    ElseIf rbtSortByField3.Checked Then
        dt.DefaultView.Sort = "Field3 ASC"
    End If

    rpt.SetDataSource(dt.DefaultView.Table)
    'This also doesn't work
    'rpt.SetDataSource(dt)
+1  A: 

ASSUMING this is a Crystal Report...

See this article. You can't sort on the datasource, you need to have the report do the sorting.

http://it.toolbox.com/blogs/coding-dotnet/sorting-the-fields-in-crystal-report-programmatically-16201

Also covered here:

http://msdn.microsoft.com/en-us/library/ms225717.aspx

David Stratton
Yep, it's Crystal Reports. I have changed the code, but am unsure of this line:FieldDef = objReport.Database.Tables("sp_LoadData").Fields("Field1")I get a non-specific "System Error" with no line number referenced. sp_LoadData is my stored procedure. objReport.Database.Tables(0).Fields("Field1") gives an "Object reference not set" error. I feel like I'm getting closer, but still not quite there.
Marty