Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Update Record

Update Record

Scheduled Pinned Locked Moved ASP.NET
databasecomhelptutorialannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jarow
    wrote on last edited by
    #1

    Hi, I have created a change password page and think I got the Update function correct but don't know how to write the "Sub button_onclick, if page is valid portion". I would like to be able to do the following: If page is valid: hide the form and create a success message. I think it would be something like the following but I don't exactly know where to put it. frmpassword.Visible = False lblUserMessage.Text = "Your password has been changed to " & strnewpass & "." If page is not valid I would like to insert a failure message - something like "could not change password, please contact administrator" Below is the update function itself. I am very much a beginner so any specific help would be greatly appreciated. many thanks Function UpdatePass(ByVal username As String, ByVal userpass As String) As Integer Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwr"& _ "oot\FAIBLogin\autores.mdb" Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString) Dim queryString As String = "UPDATE [authors] SET [userpass]='@newpass' WHERE (([authors].[username] = @usern"& _ "ame) AND ([authors].[userpass] = @userpass))" Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand dbCommand.CommandText = queryString dbCommand.Connection = dbConnection Dim dbParam_username As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter dbParam_username.ParameterName = "@username" dbParam_username.Value = username dbParam_username.DbType = System.Data.DbType.String dbCommand.Parameters.Add(dbParam_username) Dim dbParam_userpass As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter dbParam_userpass.ParameterName = "@userpass" dbParam_userpass.Value = userpass dbParam_userpass.DbType = System.Data.DbType.String dbCommand.Parameters.Add(dbParam_userpass) Dim rowsAffected As Integer = 0 dbConnection.Open Try rowsAffected = dbCommand.ExecuteNonQuery Finally dbConnection.Close End Try Return rowsAffected End Function

    M 1 Reply Last reply
    0
    • J jarow

      Hi, I have created a change password page and think I got the Update function correct but don't know how to write the "Sub button_onclick, if page is valid portion". I would like to be able to do the following: If page is valid: hide the form and create a success message. I think it would be something like the following but I don't exactly know where to put it. frmpassword.Visible = False lblUserMessage.Text = "Your password has been changed to " & strnewpass & "." If page is not valid I would like to insert a failure message - something like "could not change password, please contact administrator" Below is the update function itself. I am very much a beginner so any specific help would be greatly appreciated. many thanks Function UpdatePass(ByVal username As String, ByVal userpass As String) As Integer Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwr"& _ "oot\FAIBLogin\autores.mdb" Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString) Dim queryString As String = "UPDATE [authors] SET [userpass]='@newpass' WHERE (([authors].[username] = @usern"& _ "ame) AND ([authors].[userpass] = @userpass))" Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand dbCommand.CommandText = queryString dbCommand.Connection = dbConnection Dim dbParam_username As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter dbParam_username.ParameterName = "@username" dbParam_username.Value = username dbParam_username.DbType = System.Data.DbType.String dbCommand.Parameters.Add(dbParam_username) Dim dbParam_userpass As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter dbParam_userpass.ParameterName = "@userpass" dbParam_userpass.Value = userpass dbParam_userpass.DbType = System.Data.DbType.String dbCommand.Parameters.Add(dbParam_userpass) Dim rowsAffected As Integer = 0 dbConnection.Open Try rowsAffected = dbCommand.ExecuteNonQuery Finally dbConnection.Close End Try Return rowsAffected End Function

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      + On the design window, you can place a label control, say lblUserMessage, above the form control.The html code of the forgot password page is something like this:

      ...
      <asp:Label ID="lblUserMessage" Runat="server"></asp:Label>
      <form id="frmpassword" method="post" runat="server">
      ...

      + Remember to declare the html form control in the code-behind:

      Protected WithEvents frmpassword As System.Web.UI.HtmlControls.HtmlForm

      + In the button Click handler, you can do the update result checking:

      Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
      Dim succ As Boolean = False
      If (Page.IsValid) Then
      Dim rs As Integer = UpdatePass(txtUsername.Text, txtPassword.Text)
      If (rs > 0) Then
      succ = True
      End If
      End If

      If (succ) Then
          frmpassword.Visible = False
          lblUserMessage.Text = "Your password has been changed to ..."
      Else
          lblUserMessage.Text = "Could not change password, please contact administrator"
      End If
      

      End Sub

      If you don't know how to add the handler for the Click event in VB, take a look at Creating Event Handlers on the Windows Forms Designer[^] + You can learn more about ASP.NET in MSDN as well as from the online tutorials http://www.asp.net/Tutorials/quickstart.aspx[^]

      J 1 Reply Last reply
      0
      • M minhpc_bk

        + On the design window, you can place a label control, say lblUserMessage, above the form control.The html code of the forgot password page is something like this:

        ...
        <asp:Label ID="lblUserMessage" Runat="server"></asp:Label>
        <form id="frmpassword" method="post" runat="server">
        ...

        + Remember to declare the html form control in the code-behind:

        Protected WithEvents frmpassword As System.Web.UI.HtmlControls.HtmlForm

        + In the button Click handler, you can do the update result checking:

        Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim succ As Boolean = False
        If (Page.IsValid) Then
        Dim rs As Integer = UpdatePass(txtUsername.Text, txtPassword.Text)
        If (rs > 0) Then
        succ = True
        End If
        End If

        If (succ) Then
            frmpassword.Visible = False
            lblUserMessage.Text = "Your password has been changed to ..."
        Else
            lblUserMessage.Text = "Could not change password, please contact administrator"
        End If
        

        End Sub

        If you don't know how to add the handler for the Click event in VB, take a look at Creating Event Handlers on the Windows Forms Designer[^] + You can learn more about ASP.NET in MSDN as well as from the online tutorials http://www.asp.net/Tutorials/quickstart.aspx[^]

        J Offline
        J Offline
        jarowbear
        wrote on last edited by
        #3

        When you refer to codebehind are you referring to a separate page? How exactly do I put this at the top of my actual aspx page? Protected WithEvents frmpassword As System.Web.UI.HtmlControls.HtmlForm thanks

        M 1 Reply Last reply
        0
        • J jarowbear

          When you refer to codebehind are you referring to a separate page? How exactly do I put this at the top of my actual aspx page? Protected WithEvents frmpassword As System.Web.UI.HtmlControls.HtmlForm thanks

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Yes, this is a seperate class file. Basically, you can put your server-side code (code runs on the server) on a single web page, or seperate them in the code-behind with using the Codebehind attribute of the Page directive. Because you refer to the form control in the button Click handler that is in the code-behind, so we put that declaration inside the code-behind class as well, for example:

          Public Class ForgotPassword Inherits System.Web.UI.Page

          #Region " Web Form Designer Generated Code "
          ...
          #End Region

          Protected WithEvents frmpassword As System.Web.UI.HtmlControls.HtmlForm

          Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          'Put user code to initialize the page here
          End Sub

          ...

          End Class

          If you develop your asp.net application in VisualStudio, you are recommended to use the code-behind model as it makes your code much clearer and you can seperate layout from code. For more information, see Web Forms Code Model[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups