2016-07-28 104 views
1

我正在從sql中的存儲過程返回一個輸出參數,例如FormNo。它返回成功,我檢查過程,但在C#代碼它不會返回任何東西。爲什麼不輸出參數?

public static Boolean InsertAppliedWorks(int NITNo, int WorkNo, out int FormNo, int ContractorID, decimal FinancialMoney, int OfficeID, int OrgID) 
{ 
    Boolean status = false; 

    ClsDatabaseManager dbManager = ClsDatabaseManager.InitializeDbManager(Constants.Databases.TendersConnection); 
    try 
    { 
     FormNo = 0; 

     dbManager.Open(); 
     dbManager.CreateParameters(7); 
     dbManager.AddParameters(0, "@NIT_No", NITNo); 
     dbManager.AddParameters(1, "@Work_No", WorkNo); 
     dbManager.AddParameters(2, "@FormNo", FormNo, ParameterDirection.Output); 
     dbManager.AddParameters(3, "@Contractor_ID", ContractorID); 
     dbManager.AddParameters(4, "@FinancialMoney", FinancialMoney); 
     dbManager.AddParameters(5, "@Organization_ID", OrgID); 
     dbManager.AddParameters(6, "@Office_ID", OfficeID); 

     status = dbManager.ExecuteNonQuery("InsertAppliedWorks").ToBool(); 
    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 
    finally 
    { 
     dbManager.Close(); 
     dbManager.Dispose(); 

    } 
    return status; 
} 

代碼:

protected void btnSavePrint_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     ClsTender.InsertAppliedWorks(NitNo, WorkNo, out formno, ContractorID, Cost.ToDecimal(), bp.LoginMainOfficeID, bp.LoginOrganizationID); 

     int TestFormNo = formno; 
     Response.Redirect("/forms/general/TenderPrint.aspx?"+"NitNo="+SharedUtility.EncryptURL(NitNo.ToString())+"&WorkNo="+SharedUtility.EncryptURL(WorkNo.ToString())); 
    } 
} 

現在沒有返回的FormNo

請幫助我在此。它浪費了大量的時間,仍然沒有跡象,

回答

0

您需要使用下面的檢索值:

FormNo = Convert.ToInt32(dbManager.Parameters["@FormNo"].Value); 
+0

錯誤不能轉換字符串類型爲bool – Cuckoo

+0

@Cuckoo你的輸出參數是'FormNo' ,你需要得到它的價值。檢查編輯。 – user3185569