Skip to content

Instantly share code, notes, and snippets.

@csainty
Forked from jchannon/gist:6536653
Last active December 22, 2015 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csainty/6536769 to your computer and use it in GitHub Desktop.
Save csainty/6536769 to your computer and use it in GitHub Desktop.
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnString"].ConnectionString))
{
var parameters = model.Keywords.Select((keyword, index) => new { Name = "@P" + index, Value = keyword });
var sql = String.Format("SELECT * FROM Table WHERE Id IN ({0})", String.Join(",", parameters.Select(x => x.Name)));
connection.Open();
using (var command = new SqlCommand(sql))
{
foreach (var p in parameters)
{
command.Parameters.Add(p.Name, SqlDbType.NVarChar).Value = p.Value;
}
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment