Suppose I have a table called "Names"
ID | Name
---+--------------
1 | Bob
2 | Billy
3 | James
4 | John
5 | Tom
and on and on with thousands of names...
Suppose that I have written the following .net code to retrieve the names:
public DataSet selectFromNames()
{
const string SQL_STATEMENT =
@"SELECT Id, Name From Names;";
Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("MyConnection");
DbCommand command = db.GetSqlStringCommand(SQL_STATEMENT);
command.CommandType = CommandType.Text;
command.CommandText = SQL_STATEMENT;
DataSet ds = db.ExecuteDataSet(command);
return ds;
}
That works fine. What if I want a function that has an integer array parameter specifying the rows of the names I want to retrieve? How would I write that query?
I'm familiar with passing parameters as @parameter
, but I have no idea how to pass in an array with using the string builder to write something like where ID in (1,2,3)
which is ugly and error-prone.