adspace


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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain how to call the sql commands asynchronously in ado.net version 2.0?

996


What is the current version of entity framework?

1048