Mid From PDF ADO.NET ADO.NET

How do you perform asynchronous database operations in

DO.NET?

DO.NET supports asynchronous database operations using the async and await

keywords in C#. This allows the application to remain responsive while waiting for the

database operation to complete.

  • ExecuteNonQueryAsync: Executes a SQL command asynchronously.
  • ExecuteReaderAsync: Executes a query and returns a SqlDataReader

synchronously.

  • ExecuteScalarAsync: Executes a query and returns a single value asynchronously.

Example:

public async Task GetDataAsync()
{
SqlConnection connection = new SqlConnection(connectionString);

wait connection.OpenAsync();

SqlCommand command = new SqlCommand("SELECT * FROM Customers",

connection);

SqlDataReader reader = await command.ExecuteReaderAsync();

while (await reader.ReadAsync())

{

Console.WriteLine(reader["CustomerName"].ToString());

}

reader.Close();

}

More from ADO.NET Core Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details