Extracting selected records from Dataset
I have a Dataset of 90 records. I want to extract 30 to 40 records from the same. How can I do that
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Nov 30, 2011, 2:42 PM
Then go back to the Data Sources window. It will show you the "Entities" (such as WhateverEntities) for your database and under that the table(s). If you look in the designer (Model1.edmx) window the top of each table will have the name of a class for each record in the table. So for example the table name in the Data Sources window might be Articles (with the "s") and the designer window will show "Article" without the "s".
You can connect to the dataase with a simple "using" as in "using (WhateverEntities we = new WhateverEntities())". Then you can use LINQ to query the table, as in:
{
String s;
IEnumerable
from Result in we.Articles
where Result.Edited == false
select Result;
foreach (Article a in Results)
Console.WriteLine(String.Format("{0}|{1}|{2}", a.Article, a.Author, a.Title));
}
Or you can enumerate the records as in:
{
foreach (Article a in we.Articles)
if (a.Edited == false)
ShowArticle(a);
}
Datta KharadPosted Nov 30, 2011, 3:02 AM
You can extract 30 records from dataset using select method of dataset.
DataSet ds;
DataRow[] dr;
dr=ds.Tables["Tablename or index"].Select("Here you where condition for 30 records");
Satyapriya NayakPosted Nov 30, 2011, 12:46 AM
Use query like,
select top 30(name) from employee
select top 40(name) from employee
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select top 40(name) from employee";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "employee");
GridView1.DataSource = ds;
GridView1.DataMember = "employee";
GridView1.DataBind();
con.Close();
Thanks
Mamta MPosted Nov 30, 2011, 12:28 AM