Hi,@OmkarHcl.Welcome Microsoft Q&A.
When retrieving multiple tables into a single DataSet, the performance can be optimized in a few ways:
Batch the queries: Instead of executing each query individually, you could combine them into a single query using JOINs or UNIONs. This way, you make a single round trip to the database, reducing the overhead of multiple database calls. You can also refer to the method here.
string query = @"
SELECT * FROM Table1;
SELECT * FROM Table2;
SELECT * FROM Table3;
";
using (SqlCommand command = new SqlCommand(query, connection))
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
adapter.Fill(dataSet);
}
Asynchronous execution:SqlDataAdapter.Fill - Asynchronous approach. You could try to refer to the solution here.
List<Task> tasks = new List<Task>();
tasks.Add(Task.Run(() => FillDataSet(connection, query1, dataSet, "Table1")));
tasks.Add(Task.Run(() => FillDataSet(connection, query2, dataSet, "Table2")));
tasks.Add(Task.Run(() => FillDataSet(connection, query3, dataSet, "Table3")));
await Task.WhenAll(tasks);
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.