Results 1 to 8 of 8

Thread: Datagrid

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2000
    Posts
    19

    Red face

    Can anyone help me please, I'm using the Datagrid control, using ADO code, if I edit a record and then update it updates fine, but then I edit the same record and try updating but it gives me the following error:-

    The specified row could not be located for udpating. Some value may have been changed since it was last read.

    Thank you in advance
    Daryl
    Daryl Collins

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Posts
    253

    Lightbulb

    I think you change the value of the primary key field every time you edit a record and then it cannot be found anymore. Check what the primary key field in your table is, and avoid changing it while editing a record.

    Good Luck!!!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2000
    Posts
    19
    I've checked and it is not the primary key that changes any further help would be appreciated.

    Daryl
    Daryl Collins

  4. #4
    Addicted Member
    Join Date
    Oct 1999
    Posts
    253
    Try refreshing the DataGrid after every update.

    Good Luck!!!

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2000
    Posts
    19

    Red face

    Would you requery after columns update, your help would be appreciated.

    daryl
    Daryl Collins

  6. #6
    Addicted Member pardede's Avatar
    Join Date
    Jan 2000
    Posts
    232
    OK, here's what you need to do. After updating, you need to refresh the recordset using Resync method, and then you need to rebind your bound controls to pickup the changes to the recordset. And by the way: do not use Update to save your record, use Move(0) instead because there's a bug in the Update method of ADO. So the code is (assuming rsMyRecordset is the recordset and DataGrid1 as the bound control you use):

    Code:
    MyRecordset.Move (0) 'save to database
    MyRecordset.Resync   'requery
    
    'rebind your bound control
    Set DataGrid1.DataSource = DataGrid1.DataSource
    If you have more bound controls you can use a loop through all the bound controls to rebind them.

    Hope this helps

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2000
    Posts
    19
    How would I loop through all of my bound controls your help would be appreciated!!
    Daryl Collins

  8. #8
    Addicted Member pardede's Avatar
    Join Date
    Jan 2000
    Posts
    232
    Code will look like this:

    Code:
    Dim ctl as Control
    
    For Each ctl in frmMyForm.Controls
       If TypeOf ctl Is TextBox _
       Or TypeOf ctl Is Combobox Then
       'you can expand this with more or's...
          Set ctl.DataSource = ctl.DataSource
       End If
    Next

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