Пример #1
0
        public static int Delete(bPageComments objPageComments, SqlConnection sqlConn, SqlTransaction sqlTran)
        {
            //	construct new connection and command objects
            SqlConnection conn = sqlConn;
            SqlCommand    cmd  = DBHelper.getSprocCmd("sprocPageCommentsUpdate", 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("@PageCommentID", SqlDbType.Int);
            param.Direction = ParameterDirection.Input;
            param.Value     = objPageComments.PageCommentID;
            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);
        }
Пример #2
0
        public static int Insert(bPageComments objPageComments, SqlConnection sqlConn, SqlTransaction sqlTran)
        {
            //	construct new connection and command objects
            SqlConnection conn = sqlConn;
            SqlCommand    cmd  = DBHelper.getSprocCmd("sprocPageCommentsInsert", 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("@PageCommentID", SqlDbType.Int);
            param.Direction = ParameterDirection.Input;
            param.Value     = objPageComments.PageCommentID;
            cmd.Parameters.Add(param);

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

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

            param           = new SqlParameter("@Comment", SqlDbType.NVarChar);
            param.Direction = ParameterDirection.Input;
            param.Value     = objPageComments.Comment;
            cmd.Parameters.Add(param);

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

            param           = new SqlParameter("@Status", SqlDbType.Int);
            param.Direction = ParameterDirection.Input;
            param.Value     = objPageComments.Status;
            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
            if (retValue != 0)
            {
                objPageComments.PageCommentID = retValue;
            }
            return(retValue);
        }