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 |
What are the difference between readonly vs. Const?
What are the 4 types of classes in ADO.NET?
How we can provide data to ado.net?
What are the ADO.NET Controls?
What is the difference between connected and disconnected environment?
What are the benefits of using ado.net?
What is data relation in ado.net?
What is microsoft ole db provider for sql server?
Is it possible to edit data in Repeater control?
What are the different namespaces used in the project to connect the database? What data providers available in .net to connect to database?
How to find the count of records in a dataset?
What is sqldatareader in ado.net?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)