Results 1 to 8 of 8

Thread: Updating DBGrid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    I've got a Data Grid control that has its DataSource set to my ADO Recordset. The recordset was populated with data from a Access 2000 database. When I execute the program, the datafields are filled with the correct data as expected. When I edit the field and move to the next field, everything seems fine.

    When I exit the program, the actual database was not updated. I know the problem lies in the fact that I'm not updating changes made back to the database. I'm familiar with doing it with regular ADO, but never before with the Grid control. How can I force the data to be updated back either by a batch update or each time the cursor leaves the current field?

    Here are the settings I used:

    rs.CursorLocation = adUseClient rs.CursorType = adOpenStatic
    rs.LockType = adLockBatchOptimistic

    Tried adLockOptimistic as well..no luck. I've tried calling the following code in the Grid's Validate event:

    Grid1.Datachanged = True

    This doesn't seem to do anything for me.

    Need your help bigtime....Thanks!!

    Phil

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    Changes to a grid are reflected back to the associated ADO recordset. So you should just be able to use the Update method of the ADO recordset and it will then get updated in the db.

    Hope that helps

    Good luck,

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    You could try FormUnload or have a Save button...

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    That is what I was trying...

    I'm able to change the values and then click my save menu item. This is what I'm assuming is occuring:

    When I edit the field...nothing changes
    When I move to the next field...That changed record is moved to the DataGrid's copy buffer
    When I update my recordset, NOTHING happens because the changed data isn't in the recordsets copy buffer, but the data grid's.

    Anybody have a clue how to save the data back to the database from this datagrid. Everything I try either gives me no error messages whatsoever and looks like it updated or gives me a runtime stating "Insufficient key information"

    Thanks!!
    Phil

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    This is for a portion of my Senior project at school and is quite important. If someone would be willing to look at the code (which isn't much), i'd really appreciate it.

    I've written it in VB6 and Access2000

    Thanks!!!!!!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    Ok, I've found the problem with the recordset. Even though I'm using an Optomistic Lock and static cursor, the Recordsets's Update method is unsupported....Checked it using:

    debug.print rs.Supports(adUpdate)

    I'm pretty sure it has to do with the fact that i'm joining two tables into the recordset. Does the joining of two tables force a recordset to be unupdateable? How can I get around this?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    Here is the SQL Statement I am using:

    SELECT Transactions.Account, Account.LastName,
    Account.FirstName,
    Transactions.TotalCheck,
    Transactions.Date,
    Transactions.Processed, Transactions.Insufficient,
    Transactions.Paid
    FROM Transactions, Account
    WHERE Transactions.Account = Account.Number AND Transactions.Paid = False
    ORDER BY Transactions.Account"

    Like I said, the recordset returned is right, but its read-only despite the optomistic lock, which allows updating and is the lock I use for most access2000 projects.

    Thanks!!!!

    [This message has been edited by PhilipG (edited 01-30-2000).]

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    What event should I call the recordset's update event from?

    Thanks,
    Philip

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