For nhibernate
Session.CreateSQLQuery("exec usp_A_MySproc @aID = 1, @bID =2, @cID = 3")
or
IQuery query = Session.CreateSQLQuery("exec usp_A_MySproc @aID =:aID, @bID =:bID , @cID =:cID");
query.SetInt32("aID",1);
query.SetInt32("bID",2);
query.SetInt32("cID",3);
query.ExecuteUpdate();
or to match what you were doing
Session.CreateSQLQuery("exec usp_A_MySproc @aID =:aID, @bID =:bID , @cID =:cID")
.SetParameter("aID", 1)
.SetParameter("bID", 2)
.SetParameter("cID", 3);
For use of SqlCommand
modify the code to the following, connectionString
stands for your connection string
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("usp_A_MySproc ", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@aID", SqlDbType.Int32).Value = 1;
cmd.Parameters.Add("@bID", SqlDbType.Int32).Value = 2;
cmd.Parameters.Add("@cID", SqlDbType.Int32).Value = 3;
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
or
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("usp_A_MySproc ", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@aID", 1) ;
cmd.Parameters.AddWithValue("@bID", 2) ;
cmd.Parameters.AddWithValue("@cID", 3) ;
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
refer to MSDN article on SQLCommand how to properly add parameters
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters(v=vs.110).aspx