26ff8d9b4f
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
54 lines
2.2 KiB
C#
Executable File
54 lines
2.2 KiB
C#
Executable File
using System;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace DataModel.Helpers
|
|
{
|
|
/// <summary>
|
|
/// SQL server ADO helpers
|
|
/// </summary>
|
|
public static class SqlHelpers
|
|
{
|
|
/// <summary>
|
|
/// Binds the parameter to the command
|
|
/// </summary>
|
|
/// <param name="command">Command to bind parameter to</param>
|
|
/// <param name="parameterName">Name of parameter</param>
|
|
/// <param name="parameterValue">Value of parameter</param>
|
|
/// <returns>Bound parameter</returns>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Binds the parameter to the command
|
|
/// </summary>
|
|
/// <param name="command">Command to bind parameter to</param>
|
|
/// <param name="parameterName">Name of parameter</param>
|
|
/// <param name="parameterValue">Value of parameter</param>
|
|
/// <returns>Bound parameter</returns>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Binds the parameter to the command
|
|
/// </summary>
|
|
/// <param name="command">Command to bind parameter to</param>
|
|
/// <param name="parameterName">Name of parameter</param>
|
|
/// <param name="parameterValue">Value of parameter</param>
|
|
/// <returns>Bound parameter</returns>
|
|
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);
|
|
}
|
|
}
|
|
}
|