Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Emailing a randomly generated Password
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Emailing a randomly generated Password

 Post Reply Post Reply Page  123>
Author
IrishNewbie View Drop Down
Newbie
Newbie


Joined: 06 November 2003
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote IrishNewbie Quote  Post ReplyReply Direct Link To This Post Topic: Emailing a randomly generated Password
    Posted: 18 November 2003 at 10:12am

Guys,

I have my site working so that when someone enters there ID and hits Login a random 10 char password is generated and its stored with their id in the DB.  I also have email from a page StdMail.aspx working but i have the adress of the recipient hard coded in.  What Im trying to do is pass the UserID from Login.aspx to StdMail.aspx, Open a connection to the DB, retrieve the Email Address of the User and then email them their new password. 

My Code looks like:

<code>

<%@ Page Language ="VB" Debug="True" %>
<%@ Import Namespace="System.Web.Mail" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>

<html>
<body>
 <script runat = server>


     Dim UserID As Integer

     UserID = Request.Querystring("txtUserID")

 
 Response.Write(UserID)

  Dim aConnection As OleDbConnection = New OleDbConnection
         Dim aConnectionString As String
         Dim aQuery As String
  Dim UserEmail As String
         aConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\DB\records.mdb"
         aConnection.ConnectionString = aConnectionString
         Dim aCommand As OleDbCommand = New OleDbCommand
         aConnection.Open()
         aQuery = "Select EmailName From Students Where UserID = "& UserID &""
         aCommand.Connection = aConnection
         aCommand = New OleDbCommand(aQuery, aConnection)
         aCommand.ExecuteNonQuery()
 


 


     
</script>
 <%
 'Send an email address with product information
   
   Dim BodyFormat As String = MailFormat.Html
   Dim EmailTo As String = someone@somewhere.com
   Dim EmailFrom As String = "CSIS@hotmail.com"
  Dim EmailBody As String
 Dim EmailSubject As String = "Password For Login"

 EmailBody = "Just a Test Email!!!"


   'Send the message
 SmtpMail.smtpserver = "gabriel.ul.ie"
  SmtpMail.Send(EmailFrom, EmailTo, EmailSubject, EmailBody)

   'Display notification of mail being sent
 Response.Write(UserID)

  Response.Write("<font color=red><b>Your Password Has been sent to you! Thank you!</b></font>")
 %>
</body>
</html>

</code>

I dont know what to put into EMailTo in order to reference it to the EMailName from the DB. Anyone shed any light on this???

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2003 at 10:32am

will you pleeeeeeeeeeeeeease read this 4guys article....  you'd get so much help if you had a clue of what commands to use

"aCommand.ExecuteNonQuery()"

does not return data.. so you cannot ask the database "give me this information" and use the ExecuteNonQuery() method because it returns nothing but how many rows got affected

seriously man, you need to do some research

Contribute to the working anarchy we fondly call the Internet
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2003 at 12:33pm
I reckon if we copy and paste the last few topics we will get a working login system
Back to Top
IrishNewbie View Drop Down
Newbie
Newbie


Joined: 06 November 2003
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote IrishNewbie Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2003 at 2:32pm
Ok MorningZ, I've been reading that tutorial you suggested, I realise that the ExecuteScalar() command is what i should be using.  If I say something Like Dim EmailTo As String = aCommand.ExecuteScalar() after I use the select statement, how do i use the variable EmailTo in the body of my html page within asp tags?? I keep getting the error that it isnt declared.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2003 at 2:44pm

As far as i can see you don't have a datareader, http://www.4guysfromrolla.com/webtech/chapters/ASPNET/ch06.2 .shtml for more info.

Then you would use Dim EmailTo As String  = dr.item("email") where dr is your datareader and email is  your email address field.

Back to Top
IrishNewbie View Drop Down
Newbie
Newbie


Joined: 06 November 2003
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote IrishNewbie Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2003 at 2:48pm
But if its only one variable being returned cant i just use ExecuteScalar()????
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2003 at 3:04pm

You need to use a datareader or the other one (i forgot what its called) to read form the db! I havent used ExecuteScalar() so i don't know what it does. I do know you can just use ExecuteReader() even if its one record.

Remember that when using a DataReader you must call Read() before obtaining data.

Back to Top
IrishNewbie View Drop Down
Newbie
Newbie


Joined: 06 November 2003
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote IrishNewbie Quote  Post ReplyReply Direct Link To This Post Posted: 18 November 2003 at 3:41pm

Dim aReader As OleDbDataReader
Line 25: aReader = aCommand.ExecuteReader()
 can you tell me mart what this means

Data type mismatch in criteria expression

 

 

 

Back to Top
 Post Reply Post Reply Page  123>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.