title: Insert value into row in linq vb by calling record
body: <p>I have a LINQ VB.NET project.  I have a table "User".  I enter all the user details into the table.  This includes and email address.  I have a method which randomly generates a password.  I have another method which calls an email address, based on what has been entered in a text box, and sends the password to that email address.  My problem is that I can't figure out how to insert the newly generated password into the row belonging to the email address I have just called.  The text box that the email address is entered into is "txtEmail".  It can be assumed that the entry a "User" has already been completed, minus the password.  The following method generates the password:</p>
  
  <pre><code>Public Function GeneratePassword() As String
  
      'String variables tells how many characters password will contain.
      Dim PasswordLength As Int16 = "12"
  
      'Empty string will hold randomly generated password
      Dim NewPassword As String = ""
  
      'Characters allowed in this new password
      Dim allowedChars As String = ""
      allowedChars = "1,2,3,4,5,6,7,8,9,0"
      allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,"
      allowedChars += "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,"
  
      'Declare array to house each character generated from allowed list of characters
      Dim sep As Char() = {","c}
      Dim arr As String() = allowedChars.Split(sep)
  
      Dim IDString As String = ""
      Dim temp As String = ""
  
      'utilize the "random" class
      Dim rand As New Random()
  
      'loop through the character generation process until PasswordLength is met
      For i As Integer = 0 To Convert.ToInt32(PasswordLength) - 1
          temp = arr(rand.[Next](0, arr.Length))
          IDString += temp
  
          NewPassword = IDString
      Next
  
      'places new password in variable
      Return NewPassword
  End Function
  </code></pre>
  
  <p>Following on from that the following method fetches the email address from the database, calls the "GeneratePassword" method and emails the password to the user.  It does not save the password to the database, which is the problem I have.</p>
  
  <pre><code>Protected Sub btnPassword_Click(sender As Object, e As System.EventArgs) Handles btnPassword.Click
      If True Then
  
          'establish connection with database
          Dim db As New OrionDataClassesDataContext()
  
          '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.Users
                                                 Where u.Email = SearchUserEmail
                                                 Select u.Email).FirstOrDefault
  
          'calls generatepassword method
          Dim stNewPassword As String = GeneratePassword()
  
  
          'create new mailmessage to construct and sendemail
          Dim Mail As New MailMessage
          Try
              Mail.Subject = "Your Password Has Been Reset"
  
              'gets email address from database when user enters it
              Mail.To.Add(GlobalVariables.CurrentEmailAddress)
              'address for email to be sent from
              Mail.From = New MailAddress("XXX@XXXX.com")
  
              Mail.Body = "Your new pasword is:  " + stNewPassword + ".  Please keep this safe."
  
              'define smpt server to be used
              Dim SMTP As New SmtpClient("smtp.gmail.com")
              SMTP.EnableSsl = True
  
              'authenticate connection with smpt server and email address
              SMTP.Credentials = New System.Net.NetworkCredential("XXXX@XXX.com", "XXXXX")
  
              SMTP.Port = 587
  
              SMTP.Send(Mail)
  
              'alert when message is sent correctly
              MsgBox("Email sent successfully!")
              txtEmailAddress.Text = ""
  
          Catch ex As Exception
              'displays error message when email is not sent
              MsgBox("Email not sent - Check address")
              txtEmailAddress.Text = ""
          End Try
  
  
      End If
  End Sub
  </code></pre>
  
  <p>I have been playing around with a few scenarios but I always seem to end up just trying to create a brand new row entry, which is not what I want to do.  Any advice would be appreciated.  </p>