locked
Trying to update record via SqlCommand with .Text value RRS feed

  • Question

  • User320184449 posted

    I'm trying to update a record by using the following code but it's not updating it, the value stays the original database value.  Anyone have a clue why?  I'm stumped and tired as hell so I'm sure this is easy but it's not coming to me right now:

    Page Load:
    If Not IsDBNull(dr("custname")) Then
      nameTB1.Text = dr("custname")
    End If
    OnClick:
    SET [custname] = '" & nameTB1.Text & "'


     

    Wednesday, June 16, 2010 1:23 PM

Answers

  • User-1995538749 posted

    I'm not sure if this is your problem, but one of the most common causes of this problem is that the data is being loaded into your TextBox each and every postback instead of just on the initial page load. Make sure that you are only loading your data within a Not IsPostBack clause. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 16, 2010 1:47 PM

All replies

  • User-1995538749 posted

    I'm not sure if this is your problem, but one of the most common causes of this problem is that the data is being loaded into your TextBox each and every postback instead of just on the initial page load. Make sure that you are only loading your data within a Not IsPostBack clause. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 16, 2010 1:47 PM
  • User320184449 posted

     LOL, that did it.  I can't believe I missed that, I've used this code several other places and just kept overlooking that part.  Thought maybe it was .NET 4 that I just upgraded.  Thanks so much..

    Wednesday, June 16, 2010 1:53 PM
  • User1281381861 posted

    Ecbruck is right. Yes I have seen this type of issue many times and programmers miss the IsPostback check at the page load while applying their logic at the page load. For IsPostback you can refer http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback.aspx

    Wednesday, June 16, 2010 1:59 PM