locked
Update from textBox.text not updating records in Access 2007 RRS feed

  • Question

  • User1535393768 posted

    My update command isn't updating my records.  But if I will work when I hard code in variables.  Break Down: First the page loads the first and last name that I want to edit.. that works fine but it's the update function that isn't working but I not getting an error or nothing.  I did a little troubleshooting where if I make a variables and using those instead of someTextBoxName.text it works but using my textbox.text doesn't do anything.  Please help.

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    
            'Dim recordIndentifier, adminID, userID As String
            Dim ConnString As String = BaseClass.GetConnString
            Dim CurrentUser As String = HttpContext.Current.User.Identity.Name.Substring(3)
    
            recordIndentifier = Request.QueryString("indentifier") 'QS gets Indentifier across tables  
            adminID = Request.QueryString("admin") 'OS gets the adminID 
            userID = Request.QueryString("UserID") 'QS gets Indentifier across tables
    
            Dim UserSelectionSQL As String = _
           "SELECT FirstName, LastName FROM NameUsers WHERE NameUsers.ID =" & userID & ""
    
            Using conn As New OleDbConnection(ConnString)
                Using cmd As New OleDbCommand(UserSelectionSQL, conn)
                    cmd.CommandType = Data.CommandType.Text
                    conn.Open()
                    Using reader As OleDbDataReader = cmd.ExecuteReader()
                        While reader.Read()
    
                            FNtb.Text = reader("FirstName").ToString
                            LNtb.Text = reader("LastName").ToString
                            
                        End While                
                    End Using
                    cmd.ExecuteNonQuery()
                    conn.Close()
                End Using
            End Using
    
        End Sub
    
        Protected Sub submitBTN_Click(sender As Object, e As System.EventArgs) Handles submitBTN.Click
            Dim ConnString As String = BaseClass.GetConnString
            
            Dim SQLUpdateUserName As String = _
                    "Update NameUsers Set FirstName = ?, LastName = ? where ID = " & userID & ""
    
                    Using conn As New OleDbConnection(ConnString)
                Using cmd As New OleDbCommand(SQLUpdateUserName, conn)
                    cmd.Parameters.AddWithValue("FirstName", FNtb.Text)
                    cmd.Parameters.AddWithValue("LastName", LNtb.Text)
                    conn.Open()
                    cmd.ExecuteNonQuery()
                    conn.Close()
                End Using
            End Using
            rankLabel.Text = "test"
            'Response.Redirect("UserItems.aspx?indentifier=" & recordIndentifier & "&UserID=" & userID)
    End Sub

    Thank you,

    LMB

    Tuesday, October 2, 2012 1:41 PM

Answers

  • User-1716253493 posted
    Protected Sub submitBTN_Click(sender As Object, e As System.EventArgs) Handles submitBTN.Click 
            userID = Request.QueryString("UserID")
            Dim ConnString As String = BaseClass.GetConnString 
                    Dim SQLUpdateUserName As String = _ 
                    "Update NameUsers Set FirstName = ?, LastName = ? where ID = ?" 
                    Using conn As New OleDbConnection(ConnString) 
                Using cmd As New OleDbCommand(SQLUpdateUserName, conn) 
                    cmd.Parameters.AddWithValue("FirstName", FNtb.Text) 
                    cmd.Parameters.AddWithValue("LastName", LNtb.Text) 
                    cmd.Parameters.AddWithValue("UserID", UserID) 
                    conn.Open() 
                    cmd.ExecuteNonQuery() 
                    conn.Close() 
                End Using 
            End Using 
            rankLabel.Text = "test" 
            'Response.Redirect("UserItems.aspx?indentifier=" & recordIndentifier & "&UserID=" & userID) 
    End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 2, 2012 9:20 PM

All replies

  • User-1716253493 posted
    Protected Sub submitBTN_Click(sender As Object, e As System.EventArgs) Handles submitBTN.Click 
            userID = Request.QueryString("UserID")
            Dim ConnString As String = BaseClass.GetConnString 
                    Dim SQLUpdateUserName As String = _ 
                    "Update NameUsers Set FirstName = ?, LastName = ? where ID = ?" 
                    Using conn As New OleDbConnection(ConnString) 
                Using cmd As New OleDbCommand(SQLUpdateUserName, conn) 
                    cmd.Parameters.AddWithValue("FirstName", FNtb.Text) 
                    cmd.Parameters.AddWithValue("LastName", LNtb.Text) 
                    cmd.Parameters.AddWithValue("UserID", UserID) 
                    conn.Open() 
                    cmd.ExecuteNonQuery() 
                    conn.Close() 
                End Using 
            End Using 
            rankLabel.Text = "test" 
            'Response.Redirect("UserItems.aspx?indentifier=" & recordIndentifier & "&UserID=" & userID) 
    End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 2, 2012 9:20 PM
  • User1535393768 posted

    Thank you!!!  This worked. 

    Wednesday, October 3, 2012 10:02 AM