How to ger Selected Records From Dataset ?

Posted by Nandkishorre under ASP.NET on 8/19/2013 | Points: 10 | Views : 664 | Status : [Member] | Replies : 3
Hi to all,

I retrived data from database. The data is

ID Speed
1 40
2 30
3 0
4 0
5 0
6 0
7 20

Here my problem is how to get the Speed = 0 records as one record in another dataset. see bleow output

ID Speed
1 40
2 30
3 to 6 0
7 20

Could anyone guide me how to get this output to another dataset.


Records
Nanda Kishore.CH




Responses

Posted by: Ssj_Kumar on: 8/19/2013 [Member] Starter | Points: 25

Up
0
Down
you can't directly get the result, I required some more clarity

Input
ID Speed
1 40
2 0
3 20
4 0
5 60

what is your expected output?


Regards,
Jayakumar Selvakani

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 8/19/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Please elaborate it more

If this post helps you mark it as answer
Thanks

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 8/20/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this Code

here split out data 2 Daatview


DataSet ds=new DataSet();
DataTable Dt = new DataTable();
DataRow dr;
ds.Tables.Add(Dt);
ds.Tables[0].Columns.Add("ID");
ds.Tables[0].Columns.Add("Speed");
ds.Tables[0].TableName = "Test";

dr = ds.Tables[0].NewRow();
dr[0] = "1";
dr[1] = "40";
ds.Tables[0].Rows.Add(dr);

dr = ds.Tables[0].NewRow();
dr[0] = "2";
dr[1] = "30";
ds.Tables[0].Rows.Add(dr);

dr = ds.Tables[0].NewRow();
dr[0] = "3";
dr[1] = "0";
ds.Tables[0].Rows.Add(dr);

dr = ds.Tables[0].NewRow();
dr[0] = "4";
dr[1] = "0";
ds.Tables[0].Rows.Add(dr);

dr = ds.Tables[0].NewRow();
dr[0] = "5";
dr[1] = "0";
ds.Tables[0].Rows.Add(dr);

dr = ds.Tables[0].NewRow();
dr[0] = "6";
dr[1] = "60";
ds.Tables[0].Rows.Add(dr);
ds.Tables[0].DefaultView.RowFilter="Speed>0";
DataView dv1 = ds.Tables[0].DefaultView;

DataView dv = new DataView(ds.Tables[0]);
dv.RowFilter="speed=0";
DataSet newDataset = new DataSet();
DataTable dt1 = new DataTable();
dt1 = dv.ToTable();
newDataset.Tables.Add(dt1);


Mark as Answer if its helpful to you

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response