TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ariel Poh Choo
NA
1
872
Error in select statement - no value given for a parameter
Dec 18 2014 1:05 AM
I wanted to send an auto email to the user regarding his/her password after he/she has entered the username. But i ran into an error that states: "
No value given for one or more required parameters.
" at the statement "
using (OleDbDataReader reader = cmd.ExecuteReader())
".
The following is my codes:
string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\inetpub\wwwroot\myfolder\mydatabase";
string password = "";
string accountemail = "";
using (OleDbConnection con = new OleDbConnection(str))
{
using (OleDbCommand cmd = con.CreateCommand())
{
cmd.CommandText = "SELECT password, email FROM [users] WHERE username = @user";
cmd.Parameters.Add("@user", OleDbType.VarChar).Value = Request.Form["username"];
con.Open();
using (OleDbDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
password = reader["password"].ToString();
accountemail = reader["email"].ToString();
}
//reader.Close();
}
//con.Close();
}
}
string fromaddress = "myemail"; //send from admin/mail server
string toaddress = accountemail; //send to respective user
string subject = "forgot password";
string body = String.Concat("This is the password that you have requested: ", password, ". Please do not reply, this is an automated email."); //content of the email
try
{
var fromAddress = new MailAddress(fromaddress);
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient();
MailAddressCollection m = new MailAddressCollection();
m.Add(toaddress);
mail.Subject = subject;
mail.From = new MailAddress(fromaddress);
mail.Body = body;
mail.IsBodyHtml = true;
mail.ReplyToList.Add(fromAddress);
mail.To.Add(m[0]);
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential(fromaddress, "mypassword");
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
smtp.Send(mail);
MessageBox.Show("Success, your password has been sent to you.");
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.Redirect("Login.aspx", false);
}
}
Reply
Answers (
2
)
c#
Search Box Functionality