我想对业务逻辑层的强类型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() 也会报错
以下是代码:
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() 也会报错
解决方案 »
- .net打印问题
- 编译器错误消息
- 关于写文件,拒绝访问的原因。急~~~~~
- 请教 DropDownList 和 TextBox 取值和赋值问题
- 急:ObjectDataSource的数据源排序问题!
- 如何通过自定义MemberShipProvider来实现永久登陆或在一定时间内保持登陆状态
- Dropdownlist绑定了数据后如何做到"可以选择被绑定的数据,又可以像文本框一样输入新的数据?"
- UserControl中的控件能否关闭整个窗口?
- ASP访问数据库的问题,这个问题我百思不的其解。
- 各们高手,有什么办法解决在C#中的大小写问题!
- 服务器一上传新的 dll 就 Compiler Error Message,过一会儿就好了,怎么回事?
- DataList显示行问题
这句可能有误
EZDData.ExamInfoDataTable是什么类型?把DataView转换成EZDData.ExamInfoDataTable类型。
NewExamInfos.AcceptChanges();
/// 从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;
}
NewExamInfos.AcceptChanges(); 我改成上面的代码会提示出错异常详细信息: System.IndexOutOfRangeException: 无法找到列 order by ExamLevel。
EZDData.ExamInfoDataTable 是强数据集类型,在底层DAL定义的。
把DataView转换成EZDData.ExamInfoDataTable类型 到底怎么转换啊?