Hope it helps:
public ActionResult Index()
{
string connectionString = "Data Source=Whatever; Initial Catalog=Northwind; Integrated security=True;";
string commandText = "select" +
" _c.CompanyName" +
" from Customers _c" +
" inner join Orders _o on _o.CustomerID = _c.CustomerID" +
" Where _o.ShipCity = @city";
List<string> result = new List<string>();
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand(commandText, connection);
cmd.Parameters.Add("@city", SqlDbType.NVarChar);
cmd.Parameters["@city"].Value = "Madrid";
connection.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
result.Add(reader.GetString(0));
}
}
}
return View(result);
}
</string></string>