How can you sort a DataSet?

 Posted by Ddd on 2/16/2011 | Category: ADO.NET Interview questions | Views: 2812 | Points: 40
Answer:

DataView provides us with the Sort property

example:


 private void button1_Click(object sender, EventArgs e)

{
DataView dv = new DataView(ds.Tables["demo"]);
dv.Sort = "productname";
dataGridView1.DataSource = dv;

}
}


Note:

ds is the object reference of the DataSet
"demo" is the DataTable an stores a copy of the poducts table from the
Northwind database.
This example will sort the DataGridView on the basis of productname column.
first we have to connect using SqlConnection and use SqlDataAapter for the
query


| Alert Moderator 

Comments or Responses

Posted by: Akiii on: 7/7/2011 | Points: 10
dataGridView1.DataBind();

Should be called after assigning the datasource...

Akiii

Login to post response