I want to use something similar like this:
using (DataSet ds = new DataSet())
{
SqlParameter[] dbParams = new SqlParameter[]
{
Just use a list instead:
var parameters = new List<SqlParameter>
{
new SqlParameter("@PromptID", promptID)
};
if (scenarioID != 0)
{
parameters.Add(new SqlParameter("@ScenarioID", scenarioID));
}
If you really need an array at the end, you can always use:
var array = parameters.ToArray();
You should use List instead of array.
List<SqlParameter> dbParams = new List<SqlParameter>();
and then you can do
dbParams.Add(new SqlParameter("@PromptID", promptID);
var parameters = new List<SqlParameter>
{
new SqlParameter("@PromptID", promptID),
};
Other suggestion:
SqlParameter[] sqlPar = new SqlParameter[1];
sqlPar[0] = new SqlParameter("@System", "Teste");
If you know the maximum number of items (instanses of SQLParameter
type) then following approach is ideal. Else you can go with List<SqlParameter>
approach, which is briefed by peers.
var dbParams = new SqlParameter[2];
dbParams.SetValue(new SqlParameter("@PromptID", promptID),0);
dbParams.SetValue(new SqlParameter("@ScenarioID", scenarioID), scenarioID != 0 ? 1 : 0);