Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
try
{
    if (txtEmail.Text.Trim() != "")
    {
        MailMessage Msg = new MailMessage();
        // Sender e-mail address.
        Msg.From = new MailAddress("dkotagiri@technocratsdomain.com");
        // Recipient e-mail address.
        Msg.To.Add(txtEmail.Text);
        Msg.Subject = "Your Password Details";
        Msg.Body = "Hi, <br />Please check your Login Detailss<br /><br />Your Username: " + ds.Tables[0].Rows[0]["PrimaryEmail"] + "<br /><br />Your Password: " + ds.Tables[0].Rows[0]["Password"] + "<br /><br />";
        //Msg.Body = "hi";
        Msg.IsBodyHtml = true;
        // your remote SMTP server IP.
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "66.203.144.99";
        smtp.Port = 25;
        smtp.Credentials = new System.Net.NetworkCredential("dkotagiri@technocratsdomain.com", "Microsoft123#");
        smtp.EnableSsl = true;
        ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
        smtp.Send(Msg);
        //Msg = null;
        lbltxt.Text = "Your Password Details Sent to your mail";
        // Clear the textbox valuess
        txtEmail.Text = "";
    }
    else
    {
        lbltxt.Text = "The Email you entered not exists.";
    }
}
catch (Exception ex)
{
}
Posted
Updated 8-Apr-13 22:09pm
v2
Comments
Prasad Khandekar 9-Apr-13 4:15am    
How about doing a check whether the dataset indeed contains more than 0 tables (ds.Tables.count) and that each table contains more than 0 rows. Since you have not provided the code which shows how this dataset is populated it;s difficult to say why this error is occurring. The error means now rows are present in the table.

1 solution

This means ds.Tables[0] doesn't contains any rows. Check whether the row exists or not before using it.
Try this:
C#
if(ds.Tables[0].Rows.Count > 0){
    Msg.Body = "Hi, <br />Please check your Login Detailss<br /><br />Your Username: " + ds.Tables[0].Rows[0]["PrimaryEmail"] + "<br /><br />Your Password: " + ds.Tables[0].Rows[0]["Password"] + "<br /><br />";
}


--Amit
 
Share this answer
 
Comments
Wassim Brahim 9-Apr-13 4:26am    
Same Solution with better condition.

if(ds.Tables[0].Rows.Any()){
Msg.Body = "Hi, <br />Please check your Login Detailss<br /><br />Your Username: " + ds.Tables[0].Rows[0]["PrimaryEmail"] + "<br /><br />Your Password: " + ds.Tables[0].Rows[0]["Password"] + "<br /><br />";
}
_Amy 9-Apr-13 4:33am    
Both the conditions will return true if datatable contains any row. I couldn't find anyt difference in this condition.
Dhritirao's 9-Apr-13 4:52am    
thanku all i got the solution. its my mistake i didnt check in database.
_Amy 9-Apr-13 5:12am    
You should check the conditions in front-end also.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900