Permalink
Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (23 sloc) 1.04 KB

.NET

Use the SqlCommand object to specify and add parameters.

using System.Data.SqlClient;

var connection = new SqlConnection("[connection string]");
connection.Open();

// Anything prefaced with "@" is a parameter which can be added and resolved later
var command = new SqlCommand("SELECT * FROM table WHERE field = @value")
{
  Connection = connection();
};

// Resolve the parameter by giving it the actual value to use...
command.Parameters.AddWithValue("value", "the actual value");
var dataReader = command.ExecuteReader();

Reference:

Articles:

To do

  • Add some narrative
  • Show code examples