コード例 #1
0
        public static int Insert(bUserRoles objUserRoles, SqlConnection sqlConn, SqlTransaction sqlTran)
        {
            //	construct new connection and command objects
            SqlConnection conn = sqlConn;
            SqlCommand    cmd  = DBHelper.getSprocCmd("sprocUserRolesInsert", conn);

            cmd.Transaction = sqlTran;

            SqlParameter param;

            //	Add return value param
            param           = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
            param.Direction = ParameterDirection.ReturnValue;
            cmd.Parameters.Add(param);

            //	Add params
            param           = new SqlParameter("@UserID", SqlDbType.Int);
            param.Direction = ParameterDirection.Input;
            param.Value     = objUserRoles.UserID;
            cmd.Parameters.Add(param);

            param           = new SqlParameter("@RoleID", SqlDbType.Int);
            param.Direction = ParameterDirection.Input;
            param.Value     = objUserRoles.RoleID;
            cmd.Parameters.Add(param);

            param           = new SqlParameter("@ModifyDate", SqlDbType.DateTime);
            param.Direction = ParameterDirection.Input;
            param.Value     = objUserRoles.ModifyDate;
            cmd.Parameters.Add(param);

            param           = new SqlParameter("@ModifiedBy", SqlDbType.Int);
            param.Direction = ParameterDirection.Input;
            param.Value     = objUserRoles.ModifiedBy;
            cmd.Parameters.Add(param);


            //	open connection
            conn.Open();
            //	Execute command
            cmd.ExecuteNonQuery();
            //	get return value
            int retValue = 0;

            try {
                //	get return value of the sproc
                retValue = (int)cmd.Parameters["@RETURN_VALUE"].Value;
            } catch (System.Exception) {        //	catch all possible exceptions
                retValue = 0;                   //	set retValue To 0 (all ok)
            }
            //	close connection
            conn.Close();

            //	set dirty flag To false
            return(retValue);
        }
コード例 #2
0
        public static int Delete(bUserRoles objUserRoles)
        {
            //	construct new connection and command objects
            SqlConnection conn = DBHelper.getConnection();
            SqlCommand    cmd  = DBHelper.getSprocCmd("sprocUserRolesDelete", conn);

            SqlParameter param;

            //	add return value param
            param           = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
            param.Direction = ParameterDirection.ReturnValue;
            cmd.Parameters.Add(param);

            //	Add params
            param           = new SqlParameter("@UserID", SqlDbType.Int);
            param.Direction = ParameterDirection.Input;
            param.Value     = objUserRoles.UserID;
            cmd.Parameters.Add(param);

            param           = new SqlParameter("@RoleID", SqlDbType.Int);
            param.Direction = ParameterDirection.Input;
            param.Value     = objUserRoles.RoleID;
            cmd.Parameters.Add(param);

            //	open connection
            conn.Open();
            //	Execute command
            cmd.ExecuteNonQuery();
            //	get return value
            int retValue = 0;

            try {
                //	get return value of the sproc
                retValue = (int)cmd.Parameters["@RETURN_VALUE"].Value;
            } catch (System.Exception) {        //	catch all possible exceptions
                retValue = 0;                   //	set retValue To 0 (all ok)
            }
            //	close connection
            conn.Close();

            return(retValue);
        }