如何在c#中为下面的插入代码编写更新查询

时间:2013-10-22 10:23:58

标签: c# sql-server

CS代码

int hrd1 = bl.BL_INSERT_HR_UPLOAD(FORM_ID, OFFER_ID, DOJ, NI_NUMBER, EMP_ID);

业务层

public int BL_INSERT_HR_UPLOAD(string FORM_ID,string OFFER_ID,string DOJ,string NI_NUMBER,string    EMP_ID)
{
   int hrd1 =dl.DL_INSERT_HR_UPLOAD
   (FORM_ID,OFFER_ID,DOJ,NI_NUMBER,EMP_ID);
   return hrd1;
}

数据层

public int DL_INSERT_HR_UPLOAD(string FORM_ID, string OFFER_ID, string DOJ, string NI_NUMBER, string EMP_ID)
{
        con.Close();
        con.Open();
        SqlCommand cmd = new SqlCommand("INSERT_HR_DOCUMENT_UPLOAD", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@FORM_ID", FORM_ID);
        cmd.Parameters.AddWithValue("@OFFER_ID", OFFER_ID);
        cmd.Parameters.AddWithValue("@ABSOLUTE_DOJ", DOJ);
        cmd.Parameters.AddWithValue("@NI_NUMBER",NI_NUMBER);
        cmd.Parameters.AddWithValue("@EMPLOYEE_NUMBER", EMP_ID);

        return cmd.ExecuteNonQuery();
}

请您告诉我编写更新数据库查询,因此它的外观和工作方式与上面提到的插入代码相同。仅供参考 - form_id,offer_id是FK,PK。

1 个答案:

答案 0 :(得分:0)

像这样?

UPDATE HR_TBALE set OFFER_ID=@OFFER_ID,DOJ=@ABSOLUTE_DOJ,NI_NUMBER=@NI_NUMBER,EMP_ID=@EMPLOYEE_NUMBER
WHERE FORM_ID=@FORM_ID