简体   繁体   中英

No popups and error source is rdr=cmd.executereader();

This is the OrderDetails page and after a successful purchase at shoppingcart will be brought to this page. 1) When I let the code run, the javascript popup didn't popup like it did for my other pages. 2) rdr=cmd.executereader() was the error leading to an error page 3) SELECT * OrdersView was another error. [ I edited to SELECT * FROM ordersView] * NEW ERROR * 4) All this codes gives me no error anymore. But there's no popup and there's no email being sent to the account.

My pov on this error: Some analysis. I tried both the string StrFirstName part alacartely and the session["sfirstname"] alacartely too both result in the same error. So I post the both of the extract for you to see.

I'm not really that good in c# but I believe its due to either I retrieved the database using * instead of FROM and also cause I didn't retrieve the parts I need correctly (Logic error, I presume) Anyone can direct me on this issue?

  using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.OleDb;
    using System.Net.Mail;

    public partial class OrderDetails : System.Web.UI.Page
    {

        static readonly string scriptSuccessPaymentSuccessful =
        "<script language=\"javascript\">\n" +
            "alert (\"Your payment is successful!- Thank you!\");\n" +
        "</script>";

        protected void Page_Load(object sender, EventArgs e)
        {
            OleDbConnection mDB = new OleDbConnection();
            mDB.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/App_Data/webBase.accdb");
            mDB.Open();
            Type csType = this.GetType();
            OleDbCommand cmd;
            OleDbDataReader rdr;
            string SQLRetrieve = "SELECT * FROM ordersView";
            cmd = new OleDbCommand(SQLRetrieve, mDB);
            rdr = cmd.ExecuteReader();

            while (rdr.Read() == true)
            {

                {

                    string strFirstName = rdr["CFirstName"].ToString();
                    string strLastName = rdr["CLastName"].ToString();
                    string strEmail = rdr["CEmail"].ToString();
                    string strOrderNo = rdr["oOrderNo"].ToString();
                    string strStatus = rdr["oStatus"].ToString();
                    string strPaymentMode = rdr["oPaymentMode"].ToString();
                    string strPrice = rdr["SumOfuUnitPrice"].ToString();

                    if ((string)Session["sFlag"] != "T")
                    {

                        ClientScript.RegisterStartupScript(csType, "Success", scriptSuccessPaymentSuccessful);

                        //
                        MailMessage mailMessage = new MailMessage();
                        mailMessage.From = new MailAddress("kayzelmoo@gmail.com");
                        mailMessage.To.Add(strEmail);
                        mailMessage.Subject = "DreamJagers - Successful transaction";

                        mailMessage.Body = "<b>Dear : </b>" + strFirstName + " " + strLastName + "," + "<br/>"
                            + "<b>Order No : </b>" + strOrderNo + "<br/>"
                            + "<b>Payment Mode: </b>" + "You have paid with " + strPaymentMode + "<br/>"
                            + "<b>Amount Paid: </b>" + "$SGD" + strPrice + "<br/>"
                            + "<b>Message : </b>" + "DreamJagers thank you for making the purchase with us, you can present this E-mail to any of us as a proof of receipt purchase";
                        mailMessage.IsBodyHtml = true;

                        SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
                        smtpClient.EnableSsl = true;
                        smtpClient.Credentials = new System.Net.NetworkCredential("kayzelmoo@gmail.com", "xxxxxxxxx");
                        smtpClient.Send(mailMessage);


                    }
                    else
                    {

                    }
                }
            }
        }
    }

Well for a start

SELECT * ordersView

should be

SELECT * FROM ordersView

Your code as it is would not return anything to rdr because the syntax is wrong.

This is more than likely the problem But you aren't giving us the actual errors which we would need if this is not the answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM