开发者

Can any one tell what's going wrong with my Routine

My requirement is if the user click on update data with out changing any field on the form i would like to show as No changes made and if any changes i would like to update the data

I have written a Routine for updating data as follows

CREATE DEFINER=`root`@`%` PROCEDURE `uspEmployeeFaxDetailsUpdate`(_EmpID int(11),
_FaxNumberTypeID varchar(45),
_FaxNumber decimal(10,0),
_EndDate datetime)

BEGIN

 declare p_ecount int;

  set p_ecount= (select count(1) from tblemployeefaxdetails  where
 FaxNumberTypeID=_FaxNumberTypeID and
 FaxNumber=_FaxNumber and
 EndDate='9999-12-31');

 if p_ecount=0 then

begin

 update tblemployeefaxdetails

  set

    EndDate=_EndDate WHERE EmpID=_EmpID and EndDate="9999-12-31";

    insert into tblemployeefaxdetails(EmpID,FaxNumberTypeID,FaxNumber,StartDate,EndDate) values
    (_EmpID,_FaxNumberTypeID,_FaxNumber,curdate(),'9999-12-31');

    end;
    end if;

END

I am getting some time my required message but some time it is showing the update message

This is my code on update

   oEmployeePersonalData.EmpID = EmpID;
        oEmployeePersonalData.FaxNumberTypeID = ddlFaxTypeID.SelectedItem.Text;
        oEmployeePersonalData.FaxNumber = Convert.ToInt64(txtFaxNumber.Text);
        oEmployeePersonalData.EndDate = DateTime.Today.AddDays(-1);
        if (oEmployeePersonalData.FaxDetailUpdate())
        {
            oMsg.Message = "Updated Sucessfully";
            Label m_locallblMessage;
            oMsg.AlertMessageBox(out m_locallblMessage);
            Page.Controls.Add(m_locallblMessage);
                       }
        else
        {
            oMsg.Message = "Not Sucessfully";
            Label m_locallblMessage;
            oMsg.AlertMessageBox(out m_locallblMessage);
            Page.Controls.Add(m_locallblMessage);
        }

Updated code

   public bool FaxDetailUpdate()
    {
        m_bFlag = false;
        try
        {

            m_oCmd = new MySqlCommand(StoredProcNames.tblEmployeeFaxdetails_uspEmployeeFaxdetailsUpdate, m_oConn);
            m_oCmd.CommandType = CommandType.StoredProcedure;
            m_oCmd.Parameters.AddWithValue("_EmpID", EmpID);
            m_oCmd.Parameters.AddWithValue("_FaxNumberTypeID", FaxNumberTypeID);
            m_oCmd.Parameters.AddWithValue("_FaxNumber", FaxNumber);
            m_oCmd.Parameters.AddWithValue("_EndDate", EndDate);
            if (m_oConn.State == ConnectionState.Closed)
            {
                m_oConn.Open();
            }
            if ((m_oCmd.ExecuteNonQuery()) > 0)
            {
                this.m_bFlag = true;
            }
        }
        catch (MySqlException oSqlEx)
        {
            m_sbErrMsg.Length = 0;
            m_sbErrMsg = Utilities.SqlErrorMessage(oSqlEx);
            //DB write the Error Log
            m_oErrlog.Add(m_sbErrMsg.ToString(), DateTime.Now);
        }
        catch (Exception oEx)
        {
            m_sbErrMsg = Utilities.ErrorMessage(oEx);
       开发者_StackOverflow社区     //DB write the Error Log
            m_oErrlog.Add(m_sbErrMsg.ToString(), DateTime.Now);
        }
        finally
        {
            m_oConn.Close();
        }
        return this.m_bFlag;
    }

I am not getting any error but i would like to be done as per i said

Can any one tell what changes i have to made in this


I do not really understand the routine, what the magic date 9999-12-31 represents, and why a new record is inserted every time, instead of updating the old one.

What you can do, is have the routine return a indicator if the row was changed or not, returning the value of p_ecount through a OUT parameter.

For more information on how to use OUT parameters using the .net MySql client see http://dev.mysql.com/doc/refman/5.0/en/connector-net-programming-stored.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜