从另一个数据集生成一个数据集 [英] generate one dataset from another dataset

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

问题描述

我有一个名为Tbl_Product的表

Tbl_Product
pid(int)
pname(varchar)
价格(int)
Stime(日期时间)
Ctime(日期时间)

我使用
从该表填充数据集

i have table named Tbl_Product

Tbl_Product
pid (int)
pname (varchar)
price (int)
Stime (datetime)
Ctime (datetime)

i fill dataset from this table using,

SqlConnection con=new SqlConnection(Conn String);

Dataset ds=new Dataset();
con.open();
SqlDatAdapter adp=new SqlDatAdapter("select * from Tbl_Product",con);
adp.fill(ds);
con.close()



现在我的数据集ds组成
pid,pname,price,Stime,Ctime

但我想生成另一个包含
的数据集
pid,pname,价格,(SystemDatetime-Ctime)

我想生成另一个数据集,因为我想一次在pageLoad加载第一个数据集
但我想根据系统时间重新加载另一个数据集
我想使用updatepanel计时器重新加载每一秒.....

所以...我怎么能产生
感谢



now my dataset ds consist
pid,pname,price,Stime,Ctime

but i want to generate another dataset which consist

pid, pname,price,(SystemDatetime-Ctime)

another dataset i want to generate because i want to load first dataset at one time at pageLoad
but i want to reload another dataset based on system time
i want to reload each and every second using updatepanel timer.....

so...how can i generate
thanks

推荐答案


为此,您可以使用Linq到DataSet.看一下这个样本:
Hi,
In order to do that you can use Linq to DataSet. Take a look at this sample:
DataTable t1 = new DataTable();
           t1.Columns.Add("key1");
           t1.Columns.Add("c1");
           t1.PrimaryKey = new[] { t1.Columns["key1"] };
           t1.Rows.Add(1, "data1");





var t3 = t1.AsEnumerable();
          var t4 = t3.Select(rec => new
          {
              key1 = rec["key1"],
              c1 = rec["c1"],
              Time = DateTime.Now.ToString() + rec["c1"].ToString(),
          }).ToList();



使用上面的代码,您可以查询预定义的DataTable并向新生成的DataTable添加或删除新列.

希望对您有帮助,
干杯.



using above code you can query a pre defined DataTable and add or remove new columns to the newly generated DataTable.

I hope it helps,
Cheers.



如果您要定期填充数据集,请编写Web服务并调用它.在此Web服务中编写代码以从数据库中获取数据并将其填充到数据集中.
如有问题请给予答复

祝你好运

if u want fill dataset at regular interval then write web service and call it. in this web service write code to fetch data from database and fill it in dataset.
if any problem give reply

Best Luck


这篇关于从另一个数据集生成一个数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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