数据集数据表问题... [英] DataSet DataTable Problem...

查看:64
本文介绍了数据集数据表问题...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只有一行的数据集,并且我在gridView的中间.现在,我必须将DataList与将从gridView Rows生成的一些DataSet Rows绑定.

我已经使用过像Dis
这样的DataTable

I have a DataSet that has only one row, and I''m in the middle of a gridView. Now I have to bind a DataList with some of the DataSet Rows that will be generated from the gridView Rows.

I have used a DataTable like dis

 DataTable dt = new DataTable();
foreach (GridViewRow row in GridView1.Rows)
{
// Some Lines Of Code
DataRow dr = ds.Tables[0].Rows[0];
dt.ImportRow(dr);
}
//After the foreach loop

DataSet ddss;
ddss.Tables[0] = dt;  //IS THIS RIGHT or IS THERE ANY OTHER WAY...???

DataList1.DataSource=dt;
DataList1.DataBind();




我不知道我是否解释正确.我知道吗?




>>><<<<" SORRYY GUYS>>>>><<<
实际上,我错过了提及




I don''t know whether I explained it right. Just do le''me know.




>>>><<<<<<SORRYY GUYS>>>>>><<<<<<

Actually I missed to mention that the actual error I was getting in the

"Can't Find The SPECIFIC Columns Name"


中遇到的实际错误
为了解决我用过的...



And To resolve that I used ...

dt.Columns.Add("abc", Type.GetType("System.String"));
dt.Columns.Add("def", Type.GetType("System.String"));
dt.Columns.Add("ghi", Type.GetType("System.String"));
// AND SO ON

推荐答案

您可以尝试一下.



DataTable dt = new DataTable();
dt.Columns.Add("abc",Type.GetType("System.String"));
dt.Columns.Add("def",Type.GetType("System.String")));
dt.Columns.Add("ghi",Type.GetType("System.String")));

foreach(GridView1.Rows中的GridViewRow行)
{
DataRow dr = ds.Tables [0] .Rows [0];
dt.ImportRow(dr);
}

DataSet ddss = new DataSet();
ddss.Tables.Add(dt);

DataList1.DataSource = dt;
DataList1.DataBind();
You can try this.



DataTable dt = new DataTable();
dt.Columns.Add("abc", Type.GetType("System.String"));
dt.Columns.Add("def", Type.GetType("System.String"));
dt.Columns.Add("ghi", Type.GetType("System.String"));

foreach (GridViewRow row in GridView1.Rows)
{
DataRow dr = ds.Tables[0].Rows[0];
dt.ImportRow(dr);
}

DataSet ddss = new DataSet();
ddss.Tables.Add(dt);

DataList1.DataSource = dt;
DataList1.DataBind();


尝试

Try

ddss.Tables.Add(dt);



使用添加"将起作用,您只是还没有创建实际的数据集.

更改



Using "Add" will work, you just don''t have an actual dataset created yet.

Change

DataSet ddss;







to

DataSet ddss = new DataSet();



如果不将ddss设置为新的数据集(或先前创建的数据集),则没有任何数据表可添加到其中.



Without setting ddss to a new dataset (or one that''s previously created), there''s nothing to add the datatable to.


这篇关于数据集数据表问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆