1

I'm trying to sort the data,however the names do not get sorted when I jump from one page to another.

return new dao_StudentGroupStudents().GetNewStudentbyGroup(bureauId, search, groupId, currentPage, pageSize, out totalCount);

    /// <summary>
    /// Get All the students from that Bureau.
    /// </summary>

    public DataSet GetAllStudentGroupByBureau(int? GroupId, int? BureauID)
    {
        DataSet ds = new dao_StudentGroup().GetDataSet(null, null, BureauID);
        ds.Tables[0].DefaultView.Sort = "grouptitle asc";
        return ds;
    }

I'm typing this in and now I get Cannot find column columnName.

public DataSet GetAllStudentGroupByBureau(int? GroupId, int? BureauID) { DataSet ds = new dao_StudentGroup().GetDataSet(null, null, BureauID);

ds.Tables[0].DefaultView.Sort = "columnName ASC";

DataTable dt = ds.Tables[0].DefaultView.ToTable();

return ds;

}

2
  • Is there a question here? Commented Mar 25, 2013 at 15:32
  • So then its sorted correctly on the first page? Commented Mar 25, 2013 at 15:36

4 Answers 4

5

Try this:

DataSet ds = new dao_StudentGroup().GetDataSet(null, null, BureauID);
ds.Tables[0].DefaultView.Sort = "grouptitle asc";
ds.Tables[0] = ds.Tables[0].DefaultView.ToTable();
return ds;

UPDATE

You can simply do this then:

public DataSet GetAllStudentGroupByBureau(int ? GroupId, int ? BureauID) 
{
    DataSet ds = new dao_StudentGroup().GetDataSet(null, null, BureauID);

    ds.Tables[0].DefaultView.Sort = "grouptitle asc";        
    DataTable dt = ds.Tables[0].DefaultView.ToTable();
    ds.Tables[0].Rows.Clear();
    foreach (DataRow row in dt.Rows)
       ds.Tables[0].Rows.Add(row.ItemArray);

    return ds;
}
Sign up to request clarification or add additional context in comments.

4 Comments

ds.Tables[0] produces an error. proptery or indexes system.Datadatatablescollection.this[int] Cannot be assigned to is is read only
I'm getting this error now Error 6 'BusinessObjects.StudentGroupManager' does not implement interface member 'BusinessObjects.Contracts.IStudentGroupManager.GetAllStudentGroupByBureau(int?, int?)'. 'BusinessObjects.StudentGroupManager.GetAllStudentGroupByBureau(int?, int?)' cannot implement 'BusinessObjects.Contracts.IStudentGroupManager.GetAllStudentGroupByBureau(int?, int?)' because it does not have the matching return type of 'System.Data.DataSet'. C:\workspace\DOP.IT.Training\Development\MS\BusinessObjects\StudentGroupManager.cs 11 18 BusinessObjects
The second "=" in the DataTable dt is giving me an invalid expression term and the ds. is giving me an "; expected"
@user2208126: Sorry, that was a typing mistake. I have updated the code. Try it once!
2

You can try the following. Remember, you can't assign value to ds.Table[] back. Hence you need to create a new datatable and add it to either new or existing dataset

    ds.Tables[0].DefaultView.Sort = "columnName ASC";

    DataTable dt = ds.Tables[0].DefaultView.ToTable();

5 Comments

= is giving me an invalid expression term
I'm getting this error now Error 6 'BusinessObjects.StudentGroupManager' does not implement interface member 'BusinessObjects.Contracts.IStudentGroupManager.GetAllStudentGroupByBureau(int?, int?)'. 'BusinessObjects.StudentGroupManager.GetAllStudentGroupByBureau(int?, int?)' cannot implement 'BusinessObjects.Contracts.IStudentGroupManager.GetAllStudentGroupByBureau(int?, int?)' because it does not have the matching return type of 'System.Data.DataSet'. C:\workspace\DOP.IT.Training\Development\MS\BusinessObjects\StudentGroupManager.‌​cs 11 18 BusinessObjects
I was able to compile the above code without any error. By looking at your code above, it seems that there is something else which is causing the issue.
I'm putting this in and I get Cannot find column columnName. public DataSet GetAllStudentGroupByBureau(int? GroupId, int? BureauID) { DataSet ds = new dao_StudentGroup().GetDataSet(null, null, BureauID); ds.Tables[0].DefaultView.Sort = "columnName ASC"; DataTable dt = ds.Tables[0].DefaultView.ToTable(); return ds; }
Obviously columnName means the name of the field you want to sort on. You need to change it to original column name, it was just for reference/example only
0

You could try this:

    //convert DataSet table to DataView  
    DataView dv = ds.Tables[0].DefaultView; 

    //apply the sort   
    dv.Sort = "grouptitle ASC"; 

    //save back into our dataset  
    ds.Tables[0] = dv.ToTable();  

1 Comment

ds.Tables[0] produces an error. proptery or indexes system.Datadatatablescollection.this[int] Cannot be assigned to is is read only
0

DataView dv = ds.Tables[0].DefaultView;

dv.Sort = "grouptitle ASC"; 

ds = dv.ToTable();  

try these

default it comes in ds.table[0] no need to menstion it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.