Question

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;
        }
Était-ce utile?

La solution

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..

Autres conseils

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 }

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);

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top