简体   繁体   中英

Save query results as a string vb.net

I am creating a forgot password feature for a login form. If the users username and email match whats in the database then an email containing their password needs to be sent to their email address. Once my select statements grabs the password I do not know how to convert that over into the body of the email.

cmd2.CommandText = "Select Password from tblLogin where Username = '" & UsernameTextBox.Text & "' and EmailAddress = '" & EmailAddressTextBox.Text & "'"
            pass = cmd2.ExecuteReader
            If pass.HasRows Then
                Do While pass.Read()
                    EmailMessage.Body = "Here is your password:"
                Loop
            Else
                Console.WriteLine("No rows found.")
            End If

The only thing I can think of doing is this: EmailMessage.Body = ("Here is your password: " & pass) However I still need to figure out how I can convert pass into a string containing the query result.

EmailMessage.Body = "Here is your password: " & pass.Item(0)

Since you only want the one value from the DB, look at ExecuteScalar instead of ExecuteReader .

However, as Alex commented, unencrypted passwords is really not a good idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM