Results 1 to 6 of 6

Thread: update record

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    8

    update record

    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

  2. #2
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    You would do something like...

    Sub UpdateUser(Sender as Object, E as EventArgs)
    sql = "Update USER set Name = '" & Name.Text & "' WHERE UserID = " & Request.QueryString("UserID")

    ' Code to write to db here...
    End Sub


    Then in your HTML in a server-side form tag have

    <asp:button onClick = "UpdateUser" runat = "server" />

  3. #3
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by greg_quinn
    You would do something like...

    Sub UpdateUser(Sender as Object, E as EventArgs)
    sql = "Update USER set Name = '" & Name.Text & "' WHERE UserID = " & Request.QueryString("UserID")

    ' Code to write to db here...
    End Sub


    Then in your HTML in a server-side form tag have

    <asp:button onClick = "UpdateUser" runat = "server" />
    No you would write a stored procedure if this was SQL Server.
    I hate seeing SQL on the front end client or on a web page...

  4. #4
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    Well if you looked at the user's connection string you would see the word JET in it, which means he is most likely using Access, and thus stored procedures are not an option...

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Stored Queries are, though. I read about them a few days ago.

  6. #6
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by greg_quinn
    Well if you looked at the user's connection string you would see the word JET in it, which means he is most likely using Access, and thus stored procedures are not an option...
    Did you want to put your money on that one ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width