asp.net 出现这样的代码,那里错了,应该怎么改~/?

来源:百度知道 编辑:UC知道 时间:2024/06/18 14:29:39
当 AllowPaging 设置为 true,并且选定的数据源未实现 ICollection 时,AllowCustomPaging 必须为 true,并且必须为 ID 为 DataGrid1 的 DataGrid 设置 VirtualItemCount。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Web.HttpException: 当 AllowPaging 设置为 true,并且选定的数据源未实现 ICollection 时,AllowCustomPaging 必须为 true,并且必须为 ID 为 DataGrid1 的 DataGrid 设置 VirtualItemCount。

源错误:

行 68: Dim dr As OleDbDataReader = cmd.ExecuteReader()
行 69: DataGrid1.DataSource = dr
行 70: DataGrid1.DataBind()
行 71: conn.Close()
行 72: End Sub
可以给点修补的方法吗??

数据源类型不能用吧

指定一下datakeyfield试试

Dim dt As New DataTable();
dt.Load(dr);
Me.DataGrid1.DataSource = dt;
Me.DataGrid1.DataBind();

因为OleDbDataReader没有实现ICollection接口,这种数据源不支持分页(因为AllowPaging = true)