我要再DateSet中的DateTable删除一列再绑定到DataGrid里,为什么用ds.Tables[0].Columns.RemoveAt(1);老是出错,该怎么做?
很急!!!!!!!!!
在线等!!!
解决就给分,30想送
问题点数:30、回复次数:21Top
1 楼qimini(循序渐进)回复于 2003-12-01 20:50:18 得分 0
出什么错?
Top
2 楼larrybest(拉哩梖斯特)回复于 2003-12-01 21:03:59 得分 0
DataBinder.Eval:“System.Data.DataRowView”不包含名称为 ffsbh 的属性。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Web.HttpException: DataBinder.Eval:“System.Data.DataRowView”不包含名称为 ffsbh 的属性。
源错误:
行 149: db.Close();
行 150: myDataGrid.DataSource = ds.Tables[0].DefaultView;
行 151: myDataGrid.DataBind();
行 152: }
行 153:
源文件: c:\inetpub\wwwroot\logistic\zbmanager\zhz\zhzffjl.aspx.cs 行: 151
堆栈跟踪:
[HttpException (0x80004005): DataBinder.Eval:“System.Data.DataRowView”不包含名称为 ffsbh 的属性。]
System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
logistic.zbmanager.zhz.zhzffjl.BindGrider() in c:\inetpub\wwwroot\logistic\zbmanager\zhz\zhzffjl.aspx.cs:151
logistic.zbmanager.zhz.zhzffjl.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\logistic\zbmanager\zhz\zhzffjl.aspx.cs:63
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
Top
3 楼larrybest(拉哩梖斯特)回复于 2003-12-01 21:04:56 得分 0
ffsbh 就是我要删除的列的字段Top
4 楼qimini(循序渐进)回复于 2003-12-01 21:11:23 得分 0
myDataGrid中用的是数据绑定列?Top
5 楼qimini(循序渐进)回复于 2003-12-01 21:11:46 得分 0
还是系统自动生成的?Top
6 楼larrybest(拉哩梖斯特)回复于 2003-12-01 21:26:59 得分 0
自动生成的!Top
7 楼larrybest(拉哩梖斯特)回复于 2003-12-01 21:27:23 得分 0
private void BindGrider()
{
Pagination pager = new Pagination();
// 查询,关键字为空则忽略查询
string searchString = "";
if(keywords.Text.Trim() != "")
searchString = " and "+this.GetSearchString();
//获取所有发放过的物资名称
// 数据库链接
try
{
db = new DbCommonExt();
}
catch
{
Response.Redirect("../../errPage.aspx?errCode=10004");
}
string sqlString = "SELECT ygsbh,ffsbh,jh FROM HQ_ZHZFF where fast=0 "+ searchString +" order by ygsbh,ffrq asc";
DataSet ds = new DataSet();
ds = db.GetDataSet(sqlString,"wzff");
sqlString = "SELECT DISTINCT ffwz FROM HQ_ZHZFF WHERE fast = 0"+searchString;
db.DrClose();
db.ExecuteQuery(sqlString);
DataColumnCollection cols = ds.Tables[0].Columns;
while(db.Read())
{
//加入列
string strColName = db.GetString(0);
cols.Add(strColName);
}
cols.Add("jsr");
cols.Add("ffrq");
cols["ygsbh"].ColumnName = "员工姓名";
cols["jh"].ColumnName = "警号";
cols["jsr"].ColumnName = "经手人";
cols["ffrq"].ColumnName = "发放日期";
sqlString = "SELECT ffsbh,ygsbh,ffwz,sl,je,jsr,ffrq FROM HQ_ZHZFF WHERE fast=0"+ searchString +" order by ygsbh,ffrq asc";
db.DrClose();
DataSet dsFfwz = db.GetDataSet(sqlString,"tblFfwz");
DataView dvFfwz = new DataView(dsFfwz.Tables["tblFfwz"]);
foreach(DataRow newDR in ds.Tables[0].Rows)
{
for(int i=3;i<cols.Count-2;i++)
{
//筛选记录
dvFfwz.RowFilter = " ygsbh='"+newDR[0]+"' and ffsbh='"+newDR[1]+"' and ffwz='"+cols[i].ColumnName+"'";
foreach(DataRowView drv in dvFfwz)
{
//DataRowView drv = dvFfwz[0];
if(drv["sl"].ToString() != "")
{
newDR[i] = drv["sl"];
}
else
{
newDR[i] = drv["je"];
}
newDR[cols.Count-2] = drv["jsr"];
newDR[cols.Count-1] = drv["ffrq"];
}
}
}
ds.Tables[0].Columns.RemoveAt(1);
db.Close();
myDataGrid.DataSource = ds.Tables[0].DefaultView;
myDataGrid.DataBind();
}Top
8 楼larrybest(拉哩梖斯特)回复于 2003-12-01 21:28:08 得分 0
不好意思太乱了,不看也吧Top
9 楼opeking(opeking)回复于 2003-12-01 22:00:32 得分 0
myDataGrid.DataSource=ds.Tables[0].DefaultView;这句有毛病吧,换成这个试试:
myDataGrid.DataSource=ds.Tables[0];Top
10 楼opeking(opeking)回复于 2003-12-01 22:03:32 得分 0
另外还有可能是你只是把columns中的一项删除了,但并没有在每个rows中将他们所对应的你删除的那个column属性的值删除,所以出错.
这个我也没碰到过,只是猜测而已Top
11 楼cleo(无为而为)回复于 2003-12-02 02:11:10 得分 0
仔细看看,ds.Tables[0].Columns.RemoveAt(1);删除的就是"ffsbh"这一列吧,
Top
12 楼qimini(循序渐进)回复于 2003-12-02 10:50:00 得分 0
ds.Tables[0].Columns.RemoveAt(1);
ds.AcceptChanges();Top
13 楼larrybest(拉哩梖斯特)回复于 2003-12-02 11:33:19 得分 0
ds.AcceptChanges();
这句加了,还是原来的那个错误!
Top
14 楼bankliu(水岸)回复于 2003-12-02 11:42:09 得分 0
现在我手头没有.NET环境,不过你试试
在
ds.Tables[0].Columns.RemoveAt(1);
前面加一句:
dvFfwz = new DataView(dsFfwz.Tables["tblFfwz"]);
Top
15 楼qimini(循序渐进)回复于 2003-12-02 12:36:21 得分 0
DataView dvFfwz = new DataView(dsFfwz.Tables["tblFfwz"]);
>>>改成
DataView dvFfwz = new DataView(dsFfwz.Tables["tblFfwz"].Clone());
Top
16 楼qimini(循序渐进)回复于 2003-12-02 12:41:34 得分 30
其实我还是没有看懂你的意图~~~但是可以肯定的是
DataView是和DataTalbe关联的,如果你更改了DataTable的结构肯定是会出错的
你可以试着把你的DataTable的副本做RowFilter等操作,而改变结构的DataTable仍然绑定到DataGrid。或者你说说你的需求,应该有更好的解决方法
:)
====Hope it would help you ~~~~Top
17 楼larrybest(拉哩梖斯特)回复于 2003-12-02 13:55:55 得分 0
可我的这个删除列的语句是放在最后的,这应该没有影响的呀,我刚才试了两个表都用clone做,还是不行,
qimini(循序渐进) 你的msn是??????????Top
18 楼larrybest(拉哩梖斯特)回复于 2003-12-02 15:53:48 得分 0
怎么没有人帮我回答,也没人帮我顶了!?????Top
19 楼larrybest(拉哩梖斯特)回复于 2003-12-02 15:54:16 得分 0
各位高手帮帮我呀!!!Top
20 楼qimini(循序渐进)回复于 2003-12-02 15:57:02 得分 0
qimini@msn.comTop
21 楼zhstxin(apply)回复于 2003-12-02 16:14:43 得分 0
你應該把ds.Tables[0].Columns.RemoveAt(1); 改為ds.Tables[0].Columns.RemoveAt("ffsbh");
我用過,沒問題Top




