-3

i have one project in which i want to send forgot password mail but i am not able to find user name and password from the database it is sending blank mail like UserName : and Password : i want to find user name and password from the data base in 3 tier architecture thanks in advance and this is my code....

 protected void Button1_Click(object sender, EventArgs e)
    {
        int id = MyRegistration.fgusername(txt_Email.Text.Trim());
        if (id > 0)
        {
            string sQuery = "Select UserName, Password From Registration Where EmailID = '" + txt_Email.Text + "'";

            DataSet ds =DataAccessLayer.ExeSelectQuery(sQuery);
            try
            {
                string sUserName = "";
                string sPassword = "";
                sendMail( sUserName, sPassword);
            }
            catch (Exception ex) { }
        }
        else { label1.Text = "Invalid User"; }
    }

Data Access Layer :

  public static int fgusername(string sEmailId)
        {
            int id1 = 0;
            string selectstr = "SELECT UserName, Password FROM Registration WHERE EmailID = '" + sEmailId.Trim() + "'";
            id1 = DataAccessLayer.ExecuteReader(selectstr);
            return id1;
        }
yash
  • 73
  • 1
  • 7

4 Answers4

1

what else do you expect by running this code

string sUserName = "";
            string sPassword = "";
            sendMail( sUserName, sPassword);


try
        {
            string sUserName = "";
            string sPassword = "";
            sendMail( sUserName, sPassword);
        }
        catch (Exception ex) { throw ex; // throw the exception }
TalentTuner
  • 17,262
  • 5
  • 38
  • 63
  • `mail.Body = "Hi,
    Please check your Login Details

    UserName: " + sUserName + "

    Password: " + sPassword + "

    "; mail.IsBodyHtml = true; `
    – yash Mar 18 '13 at 06:48
1
DataSet ds =DataAccessLayer.ExeSelectQuery(sQuery);
            try
            {

  if(ds .Tables[0].Rows.Count>0)
                {
  string sUserName = "";
                string sPassword = "";
                 sUserName =   ds.Tables[0].Rows[0]["Username"].ToString();
                 sPassword =   ds.Tables[0].Rows[0]["Password"].ToString();
sendMail( sUserName, sPassword);
                } 
            }

Hi Try this Hope It will help u..

Muthuram
  • 154
  • 12
0

You are setting sUsername and sPassword empty before sending mail, see below:

string sUserName = "";
string sPassword = "";

sendMail( sUserName, sPassword);

try to do like this :

string sUserName = ds.Tables[0].Rows[0]["UserName"].ToString();
string sPassword = ds.Tables[0].Rows[0]["Password"].ToString();

sendMail( sUserName, sPassword);
CodeGuru
  • 2,722
  • 6
  • 36
  • 52
  • this is because you are destroying stacktrace , throe the exception so that you can get the reason for not getting the email and how to do that see my answer below. – TalentTuner Mar 18 '13 at 06:57
  • @yash : I just given you core code, basic check you have to do, You can check there is no difference b/w above code and mine except checks. – CodeGuru Mar 18 '13 at 07:03
0

string sUserName=""; string sPassword=""; You initialize these both variable with no value and i thought your SendMail(sUserName,sPassword); is using these variable values as it is.

Codex
  • 78
  • 1
  • 2
  • 13