[英]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)但是我仍然需要弄清楚如何将pass转换为包含查询结果的字符串。
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
. 由于只需要数据库中的一个值,因此请查看ExecuteScalar而不是
ExecuteReader
。
However, as Alex commented, unencrypted passwords is really not a good idea. 但是,正如Alex所言,未加密的密码确实不是一个好主意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.