using System; using System.Data.SqlClient; namespace DataModel.Helpers { /// /// SQL server ADO helpers /// public static class SqlHelpers { /// /// Binds the parameter to the command /// /// Command to bind parameter to /// Name of parameter /// Value of parameter /// Bound parameter public static SqlParameter Bind(this SqlCommand command, string parameterName, object parameterValue) { return parameterValue != null ? command.Parameters.AddWithValue(parameterName, parameterValue) : command.Parameters.AddWithValue(parameterName, DBNull.Value); } /// /// Binds the parameter to the command /// /// Command to bind parameter to /// Name of parameter /// Value of parameter /// Bound parameter public static SqlParameter Bind(this SqlCommand command, string parameterName, string parameterValue) { return !string.IsNullOrEmpty(parameterValue) ? command.Parameters.AddWithValue(parameterName, parameterValue) : command.Parameters.AddWithValue(parameterName, DBNull.Value); } /// /// Binds the parameter to the command /// /// Command to bind parameter to /// Name of parameter /// Value of parameter /// Bound parameter public static SqlParameter Bind(this SqlCommand command, string parameterName, byte[] parameterValue) { return parameterValue != null ? command.Parameters.AddWithValue(parameterName, parameterValue) : command.Parameters.AddWithValue(parameterName, DBNull.Value); } } }