0

我有一个允许用户输入电子邮件地址的 VB.net LINQ 程序。电子邮件地址根据名为“User_signon”的数据库表进行检查,该表具有“电子邮件(PK)”和“密码”字段。单击“btnPassword”时,将根据数据库检查电子邮件地址,并将随机生成的密码通过电子邮件发送到电子邮件地址。问题是我无法弄清楚如何获取新的随机密码以在数据库中更新以连接电子邮件地址。我有以下代码,但我缺少更新密码的方法。

'与数据库建立连接 Dim db As New DatabaseDataClassesDataContext()

        'initialise global variabel to take email string entered in text box
        GlobalVariables.SearchUserEmail = txtEmailAddress.Text

        'initialise global variable to hold email address retrieved from database
        GlobalVariables.CurrentEmailAddress = (From u In db.User_Signons
                                               Where u.Email = SearchUserEmail
                                               Select u.Email).First

       'calls generatepassword method
        Dim stNewPassword As String = GeneratePassword()

请问那里有什么帮助吗?

4

2 回答 2

1

你可以这样做

Dim user= (From u In db.User_Signons Where     u.Email = SearchUserEmail Select u.Email).First;

user.password =stNewPassword
db.SaveChanges();

就是这样。

于 2013-03-06T13:50:49.853 回答
1

不只是获取用户名,而是获取整个用户对象,然后设置密码并保存结果。看看以下是否有帮助:

    'initialise global variabel to take email string entered in text box
    GlobalVariables.SearchUserEmail = txtEmailAddress.Text

    'initialise global variable to hold email address retrieved from database
    Dim user = db.User_Signons.First(Function(u) u.Email = SearchUserEmail)
    GlobalVariables.CurrentEmailAddress = user.UserEmail

   'calls generatepassword method
    Dim stNewPassword As String = GeneratePassword()
    user.Password = stNewPassword
    db.SubmitChanges()
于 2013-03-06T13:53:15.817 回答