Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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,

HTML
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()


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
Posted

Hi,
In order to do that you can use Linq to DataSet. Take a look at this sample:
C#
DataTable t1 = new DataTable();
           t1.Columns.Add("key1");
           t1.Columns.Add("c1");
           t1.PrimaryKey = new[] { t1.Columns["key1"] };
           t1.Rows.Add(1, "data1");


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


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.
 
Share this answer
 
Comments
Reza Ahmadi 9-Apr-12 3:01am    
I really thank you for your vote! and please tell me what was the reason for that vote
hi,
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
 
Share this answer
 
Comments
PKriyshnA 9-Apr-12 2:39am    
i did usig your logic but i want to reduce my load
using webservice all time webservice connect to database
but in database Ctime is static ....
'so how can i fetch it continuously
i also got directly SystemTime-Ctime
but each and every second i need to execute.....so each and every time connect to database
it takes tooo much load and did not get accurate result....
i get data ay onetime on pageload then not need to execute ...
only dataset to another dataset i need to generate ......so....
tnx for your valuable reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900