Skip to content

Instantly share code, notes, and snippets.

@dshookowsky
Created September 11, 2013 21:00
Show Gist options
  • Save dshookowsky/6529717 to your computer and use it in GitHub Desktop.
Save dshookowsky/6529717 to your computer and use it in GitHub Desktop.
Extension to add parameters to dbCommand.
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Web;
namespace CustomExtensions
{
/// <summary>
/// Add a convenient method to add parameters to a dbCommand with value.
/// </summary>
/// <remarks>
/// This method was found at http://social.msdn.microsoft.com/Forums/en-US/d56a4710-3fd1-4039-a0d9-c4c6bd1cd22e/dbcommand-parameters-collection-missing-addwithvalue-method
/// </remarks>
public static class ParameterExtension
{
public static void AddParameterWithValue(this DbCommand command, string parameterName, object parameterValue)
{
var parameter = command.CreateParameter();
parameter.ParameterName = parameterName;
parameter.Value = parameterValue;
command.Parameters.Add(parameter);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment