// Method signature declaration which accepts 2 parameters, the first a Database Command and the second an array of parameters of type Object
public static void SetParameters(this DbCommand command, object[] parms)
// Validation check to see the array of parameters is not null and of a length greater than 0
if (parms != null && parms.Length > 0)
// Loop through and add 2 to each loop???
for (int i = 0; i < parms.Length; i += 2)
// Convert the first parameter to string and store in a name variable
string name = parms[i].ToString();
// Not entirely sure
if (parms[i + 1] is string && (string)parms[i + 1] == "")
// Reset to null
parms[i + 1] = null;
// Again not entirely sure
object value = parms[i + 1] ?? DBNull.Value;
// Create the parameter object and and store in a local var named dbParameter
var dbParameter = command.CreateParameter();
// Set the name reference to the ParameterName property
dbParameter.ParameterName = name;
// Set the value reference to the Value property
dbParameter.Value = value;
// The add the dbParameter to the list of command parameters
command.Parameters.Add(dbParameter);
Thanks
VulpesPosted Mar 1, 2012, 11:57 AM
Guest UserPosted Mar 6, 2012, 11:15 AM
VulpesPosted Mar 6, 2012, 11:09 AM
http://www.dotnetperls.com/sqlparameter
Guest UserPosted Mar 6, 2012, 10:55 AM
Thanks for the breakdown of the code sample above.
Could I ask what type of Database Parameters the method is likely to receive back from the Database?
Im unsure on the whole Database Parameter concept and cannot find anything online, would it be the columns or rows etc.
cheers