-3

我有一个项目,我想在其中发送忘记密码的邮件,但我无法从数据库中找到用户名和密码,它正在发送空白邮件,如用户名:和密码:我想从数据库中查找用户名和密码在 3 层架构中提前感谢,这是我的代码....

 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"; }
    }

数据访问层:

  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;
        }
4

4 回答 4

1

通过运行此代码,您还有什么期望

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


try
        {
            string sUserName = "";
            string sPassword = "";
            sendMail( sUserName, sPassword);
        }
        catch (Exception ex) { throw ex; // throw the exception }
于 2013-03-18T06:44:11.333 回答
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);
                } 
            }

嗨试试这个希望它会帮助你..

于 2013-03-18T06:55:06.367 回答
0

您在发送邮件之前将 sUsername 和 sPassword 设置为空,如下所示:

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

sendMail( sUserName, sPassword);

尝试这样做:

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

sendMail( sUserName, sPassword);
于 2013-03-18T06:51:26.890 回答
0

字符串 sUserName=""; 字符串 sPassword=""; 您将这两个变量都初始化为没有值,我认为您的 SendMail(sUserName,sPassword); 正在使用这些变量值。

于 2013-03-18T07:03:15.647 回答