我想对业务逻辑层的强类型dataset数据排序,但都出错。在业务逻辑层应该怎么排序?用ObjectDataSource又怎么排序?
以下是代码:
    public EZDData.ExamInfoDataTable GetExams(int ExamTypeID, string[,] Proportion, int Amount)
    {
        EZDData.ExamInfoDataTable NewExamInfos = new EZDData.ExamInfoDataTable();        for (int i = 0; i < Proportion.Length / 2; i++)
        {
            EZDData.ExamInfoDataTable examInfos = new EZDData.ExamInfoDataTable();
            examInfos = Adapter.GetExamInfoByExamLevel(Convert.ToInt32(Proportion[i, 1]), ExamTypeID, Proportion[i, 0]);            NewExamInfos.Merge(examInfos);
           
        }
        
        /*
        DataView dv = NewExamInfos.DefaultView;
        dv.Sort = "ExamLevel desc";
        dv.Table.AcceptChanges();        EZDData.ExamInfoDataTable new_ExamInfos = new EZDData.ExamInfoDataTable();
        new_ExamInfos = dv.Table.Copy();
        */
        //NewExamInfos = dv.ToTable()        //NewExamInfos.DefaultView.Sort = "ExamLevel desc";
        //NewExamInfos.AcceptChanges();        return NewExamInfos;
    }new_ExamInfos = dv.Table.Copy(); 会报错NewExamInfos = dv.ToTable() 也会报错

解决方案 »

  1.   

    可以试一试:将其中转一下, GridView1.DataSource = dv; 在将GridView 给 datatable
      

  2.   

    dv.Sort = "ExamLevel desc"; 
    这句可能有误
      

  3.   

    类型不匹配?
    EZDData.ExamInfoDataTable是什么类型?把DataView转换成EZDData.ExamInfoDataTable类型。
      

  4.   

    NewExamInfos.DefaultView.Sort = " order by ExamLevel desc ";
    NewExamInfos.AcceptChanges(); 
      

  5.   

    /**//// <summary>
            /// 从GridView的数据生成DataTable
            /// </summary>
            /// <param name="gv">GridView对象</param>
            public static DataTable GridView2DataTable(GridView gv)
            {
                DataTable table = new DataTable();
                int rowIndex = 0;
                List<string> cols = new List<string>();
                if (!gv.ShowHeader && gv.Columns.Count == 0)
                {
                    return table;
                }
                GridViewRow headerRow = gv.HeaderRow;
                int columnCount = headerRow.Cells.Count;
                for (int i = 0; i < columnCount; i++)
                {
                    string text = GetCellText(headerRow.Cells[i]);
                    cols.Add(text);
                }
                foreach (GridViewRow r in gv.Rows)
                {
                    if (r.RowType == DataControlRowType.DataRow)
                    {
                        DataRow row = table.NewRow();
                        int j = 0;
                        for (int i = 0; i < columnCount; i++)
                        {
                            string text = GetCellText(r.Cells[i]);
                            if (!String.IsNullOrEmpty(text))
                            {
                                if (rowIndex == 0)
                                {
                                   string columnName = cols[i];
                                    if (String.IsNullOrEmpty(columnName))
                                    {        
                                            continue;
                                    }
                                    if (table.Columns.Contains(columnName))
                                    {
                                        continue;
                                    }
                                    DataColumn dc = table.Columns.Add();
                                    dc.ColumnName = columnName;
                                    dc.DataType = typeof(string);
                                }
                                row[j] = text;
                                j++;
                            }                    
                        }
                        rowIndex++;
                        table.Rows.Add(row);
                    }
                }
                return table;
            }
      

  6.   

    NewExamInfos.DefaultView.Sort = " order by ExamLevel desc "; 
      

  7.   

    NewExamInfos.DefaultView.Sort = " order by ExamLevel desc "; 
    NewExamInfos.AcceptChanges(); 我改成上面的代码会提示出错异常详细信息: System.IndexOutOfRangeException: 无法找到列 order by ExamLevel。
      

  8.   


    EZDData.ExamInfoDataTable 是强数据集类型,在底层DAL定义的。
    把DataView转换成EZDData.ExamInfoDataTable类型 到底怎么转换啊?
      

  9.   

    我是要把 NewExamInfos 按照 ExamLevel排序后再在GridView显示出来,该怎么处理各位大侠!