|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace AndrewGolik.DaoTraining.DataAccessLayer.MSSql
{
public static class MSSqlHelper
{
public static void AddParamToSQLCmd(SqlCommand sqlCmd,
string paramId,
SqlDbType sqlType,
int paramSize,
ParameterDirection paramDirection,
object paramvalue)
{
if (sqlCmd == null)
throw (new ArgumentNullException("sqlCmd"));
if (string.IsNullOrEmpty(paramId))
throw (new ArgumentOutOfRangeException("paramId"));
SqlParameter newSqlParam = new SqlParameter();
newSqlParam.ParameterName = paramId;
newSqlParam.SqlDbType = sqlType;
newSqlParam.Direction = paramDirection;
if (paramSize > 0)
newSqlParam.Size = paramSize;
if (paramvalue != null)
newSqlParam.Value = paramvalue;
sqlCmd.Parameters.Add(newSqlParam);
}
public static object ExecuteScalarCommand(SqlCommand command , string connectionString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
if (command == null)
throw new ArgumentNullException("Command param is null where it must be an object.");
connection.Open();
command.Connection = connection;
return command.ExecuteScalar();
}
}
public static int ExecuteNonQueryCommand(SqlCommand command, string connnectionString)
{
using (SqlConnection connection = new SqlConnection(connnectionString))
{
if (command == null)
throw new ArgumentNullException("Command param is null where it must be an object.");
connection.Open();
command.Connection = connection;
return command.ExecuteNonQuery();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Andrew Golik is a software professional working in Minsk, Belarus.
He enjoys design infrastructures based on object oriented paradigm. His programming experience includes ASP, ASP.NET, .NET, COM, JAVA, PHP, DHTML, AJAX, blah blah blah....
Andrew Golik's Blog