Here is an example C# code snippet to query SQL Server with parameters using ADO.NET:
main.cs474 chars15 lines
In this example, we are selecting all customers from the "Customers" table where the "City" column equals "London". We are using a parameterized query to prevent SQL injection attacks. The "@city" parameter is defined in the SQL command string, and its value is set using the "command.Parameters.Add" method, which also specifies the data type of the parameter. Finally, we execute the query using the "command.ExecuteReader" method and loop through the results using a SqlDataReader object.
gistlibby LogSnag