Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中检测到无法访问的函数代码#_C#_Asp.net - Fatal编程技术网

C# 在c中检测到无法访问的函数代码#

C# 在c中检测到无法访问的函数代码#,c#,asp.net,C#,Asp.net,我在下面的示例代码中发现“检测到无法访问的代码”错误。请帮我解决这个问题它和try-and-catch语句有什么关系吗?函数UpdateCommentStatus位于同一个cs文件中: public string insertEmail(string pstrEmailFrom, string pstrEmailTo, string pstrEmailSubject, string pstrEmailBody, string pstrBRID, string pstrTicketID, int

我在下面的示例代码中发现“检测到无法访问的代码”错误。请帮我解决这个问题它和try-and-catch语句有什么关系吗?函数UpdateCommentStatus位于同一个cs文件中:

public string insertEmail(string pstrEmailFrom, string pstrEmailTo, string pstrEmailSubject, string pstrEmailBody, string pstrBRID, string pstrTicketID, int include_Attachment)
    {
        // Include Attachment is for keep track of only first email notification will contain attachment.
        // This is done to conserve bandwidth and processing. 
        string strSQL;
        string strEmailSubject = pstrEmailSubject.Replace("'", "''");
        string strEmailBody = pstrEmailBody.Replace("'", "''");
        strSQL = "INSERT INTO CRM_EMAIL(email_to,email_from,email_subject,email_body,created_date,";
        strSQL = strSQL + " br_id,notes,status,ticket_id, INCLUDE_ATTACHMENT,SEG_ID) VALUES ";
        strSQL = strSQL + "('" + pstrEmailFrom.Replace("'", "") + "','" + pstrEmailTo.Replace("'", "") + "','" + strEmailSubject + "', ";
        strSQL = strSQL + "'" + strEmailBody + "',NOW(), ";
        strSQL = strSQL + "'" + pstrBRID + "','','N', '" + pstrTicketID + "', " + include_Attachment + ",'" + mag.getSegID() + "')";
        mag.WriteToNormalLogFile("insertEmail()  strSQL:" + strSQL);
        try
        {
            objDBinterface.strConn = mag.ConnStr();
            objDBinterface.ExecSQL(strSQL);
            UpdateCommentStatus(pstrTicketID);
            return "";
        }
        catch (Exception ex)
        {
            mag.WriteToLogFile("insertEmail : " + ex.ToString());
            return ex.ToString();
        }

        UpdateCommentStatus(pstrTicketID); <<-- HERE
    }
public string insertEmail(string pstrEmailFrom、string pstrEmailTo、string pstrEmailSubject、string pstrEmailBody、string pstrBRID、string pstrTicketID、int include\u附件)
{
//“包含附件”仅用于跟踪包含附件的第一封电子邮件通知。
//这样做是为了节省带宽和处理。
字符串strSQL;
字符串strEmailSubject=pstrEmailSubject.Replace(“,”);
字符串strEmailBody=pstrEmailBody.Replace(“,”);
strSQL=“插入CRM电子邮件(电子邮件收件人、电子邮件发件人、电子邮件主题、电子邮件正文、创建日期,”;
strSQL=strSQL+“br_id、注释、状态、票证id、包括附件、SEG_id)值”;
strSQL=strSQL+“(“+pstrEmailFrom.Replace”(“,”)+“,“+pstrEmailTo.Replace”(“,”)+”,“+strEmailSubject+”,”;
strSQL=strSQL+“'+strEmailBody+”,NOW(),“;
strSQL=strSQL+“““+pstrBRID+”,“,”N“,“+PSTRICKETID+”,“+include_Attachment+”,“+mag.getSegID()+”)”;
mag.WriteToNormalLogFile(“insertEmail()strSQL:+strSQL”);
尝试
{
objDBinterface.strConn=mag.ConnStr();
ExecSQL(strSQL);
更新推荐状态(pstrTicketID);
返回“”;
}
捕获(例外情况除外)
{
mag.WriteToLogFile(“insertEmail:+ex.ToString());
返回例如ToString();
}

UpdateCommentStatus(pstrTicketID)这是由于在
try
catch
块中返回,catch块之后的代码将永远不会有机会执行。您可以在
UpdateCommentStatus
调用之后的try块中移动返回,或者在
try
块中的return语句之前移动
UpdateCommentStatus

您可以在执行成功的情况下返回空字符串,如果出现错误,可以返回异常消息。您可以考虑以下选项来返回错误。

  • 将返回类型设为bool并抛出一个execption
  • 返回bool并使用out参数传递错误

你不尝试使用“using”语句吗?我想你根本不需要这一行,因为你已经在
try
中调用了
UpdateCommentStatus
。为了更好地解释错误…(请随意将此添加到你的回答Adil中)。如果try块成功,则返回方法,如果它捕获错误,则返回方法。因此,由于您已经返回,因此该代码永远不会执行