Created
September 11, 2013 21:00
-
-
Save dshookowsky/6529717 to your computer and use it in GitHub Desktop.
Extension to add parameters to dbCommand.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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