SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand("SELECT * FROM Customers WHERE City = @City", connection); command.Parameters.AddWithValue("@City", "New York"); SqlDataAdapter adapter = new SqlDataAdapter(command); DataTable customersTable = new DataTable(); adapter.Fill(customersTable);
public class Customer { public int CustomerID { get; set; } public string CustomerName { get; set; } public string City { get; set; } } string query = "SELECT * FROM Customers WHERE City = @City"; using (SqlConnection connection = new SqlConnection(connectionString)) { ListIn this example, we are retrieving the customers from the Customers table based on the City column value gathered using Dapper. Package/library: System.Data.SqlClient, Dapper.customers = connection.Query (query, new { City = "New York" }).ToList(); }