Google News
logo
ADO.NET - Quiz(MCQ)
If you are using the DataSet and you have to display the data in sorted order what will you do?
A)
Use DataViev object with each sort
B)
Use Sort method of DataTable
C)
Use Sort method of DataSet
D)
Use datapaging and sort the data.

Correct Answer :   Use DataViev object with each sort


Explanation :

DataView.Sortproperty allow you to sort data. Using a DataView, you can show the data in a table with different sort orders.

Example : In this example our table name is StudentMaster.

public partial class Default5 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("provide connection string");
SqlDataAdapter da;
protected void Page_Load(object sender, EventArgs e)
{
string query = "select * from StudentMaster";
da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
DataView dv = new DataView();
dv = ds.Tables[0].DefaultView;
dv.Sort = "studName";
DataTabledt = dv.Table;
GridView1.DataSource = dt;
GridView1.DataBind();
}
}

Advertisement