-4

这些值不会传入EmailTO和传出EmailFrom存储过程,它显示为 NULL。所以我无法发送电子邮件。如果我手动输入电子邮件地址ToFrom然后电子邮件以 smtp 形式发送,但它不是从存储过程中读取的。

请帮助我检索值:

这是我的存储过程,数据存储在表中:

    Set @EmailFrom =(SELECT EmailFrom FROM tblEmailDesign where EmailID = @EmailID )
    Set @EmailTo =(SELECT EmailTo FROM tblEmailDesign where EmailId = @EmailID )

    Insert into tblEmailsend([EmailID][EmailSubject],[EmailTo],[EmailFrom],[EmailBody],[EmailComment])
select @EmailID @EmailFrom,@EmailTo,[EmailSubject],[EmailBody],@EmailComment from tblEmaildesign
where EmailID=@EmailID

END

这是我在 C# 中的调用代码:

protected void submit(object sender, EventArgs e)

        SqlParameter EmailTo = new SqlParameter("@EmailTo", SqlDbType.NVarChar, 200);
        EmailTo.Direction = ParameterDirection.Output;
        scom.Parameters.Add(EmailTo);

        SqlParameter EmailFrom = new SqlParameter("@EmailFrom", SqlDbType.NVarChar, 200);
        EmailFrom.Direction = ParameterDirection.Output;
        string To = EmailTo;

        String FRom = EmailFrom;
        scom.Parameters.Add(EmailFrom);

        mail message = new mail();

        mailsystem.Esendmail(To,From);

        try {
            scom.Connection.Open();
            scom.ExecuteNonQuery();
            scom.ExecuteReader(CommandBehavior.CloseConnection);
        } finally {
            scom.Connection.Close();
        }
    }
}
4

1 回答 1

0

执行后,您需要从存储过程中获取输出参数值:

protected void submit(object sender, EventArgs e)

    using (SqlCommand scom = new SqlCommand("spx_Send_Status_Mail", new SqlConnection(ConfigurationManager.ConnectionStrings["EPOCHSConnectionString"].ConnectionString))) {

        scom.CommandType =CommandType.StoredProcedure;    
        SqlParameter EmailTo = new SqlParameter("@EmailTo", SqlDbType.NVarChar, 200);
        EmailTo.Direction = ParameterDirection.Output;
        scom.Parameters.Add(EmailTo);    
        SqlParameter EmailFrom = new SqlParameter("@EmailFrom", SqlDbType.NVarChar, 200);
        EmailFrom.Direction = ParameterDirection.Output;
        scom.Parameters.Add(EmailFrom);

        try {
            scom.Connection.Open();
            scom.ExecuteNonQuery();
            scom.ExecuteReader(CommandBehavior.CloseConnection);
        } finally {
            scom.Connection.Close();
        }

        mail message = new mail();

        //Get output parameters after executing query
        string to = EmailTo.Value.ToString();
        string from = EmailFrom.Value.ToString();
        //Pass To and From email addresses to the ESendmail function
        mailsystem.Esendmail(to,from);
    }
}
于 2012-07-16T06:10:26.773 回答