How to perform sorting on a table in ADO.NET?



How to perform sorting on a table in ADO.NET?..

Answer / Sanjay Sharma

To sort a table in ADO.NET, you can use the Sort command with the DataView object. Here's an example:

```csharp
using System;
using System.Data;
using System.Data.SqlClient;

class Program
{
static void Main(string[] args)
{
string connectionString = "YourConnectionString";
string sqlQuery = "SELECT * FROM YourTable";

SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter adapter = new SqlDataAdapter(sqlQuery, connection);
DataTable table = new DataTable();
adapter.Fill(table);

DataView view = table.DefaultView;
view.Sort = "YourColumn DESC"; // Sort by column in descending order
table = view.ToTable();
}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More ADO.NET Interview Questions

What are the difference between readonly vs. Const?

1 Answers  


What are the 4 types of classes in ADO.NET?

5 Answers  


How we can provide data to ado.net?

1 Answers  


What are the ADO.NET Controls?

6 Answers  


What is the difference between connected and disconnected environment?

1 Answers  


What are the benefits of using ado.net?

1 Answers  


What is data relation in ado.net?

1 Answers  


What is microsoft ole db provider for sql server?

1 Answers  


Is it possible to edit data in Repeater control?

1 Answers  


What are the different namespaces used in the project to connect the database? What data providers available in .net to connect to database?

1 Answers  


How to find the count of records in a dataset?

6 Answers  


What is sqldatareader in ado.net?

1 Answers  


Categories