Garrettchap1
Garrettchap1

Reputation: 79

SQL database unable to update using ADO

I can't get my datagrid to an editable status. I'd like to be able to load up the program, let the grid get populated and then be able to click within any cell and edit or add to it and save the changes to the data source. I've tried the common methods using the ".Update" tactic, but I had no luck. I think the first thing that needs to be fixed is my datagrid, its stuck in read-only and i'm aware of the adLockTypeOptimistic method by forcing it into read/write but I do not know where exactly to place the it within my code? Would it go in the query string ?

Upvotes: 0

Views: 272

Answers (1)

bugtussle
bugtussle

Reputation: 1416

You set the lock type in the recordset object before you populate it:

With rs
    .CursorLocation = adUseClient
    .CursorType = adOpenKeyset
    .LockType = adLockTypeOptimistic
    .Source = strSQL
    .ActiveConnection = dbConn
    .Open
End With

You may also need to set the cursorlocation property on the connection object prior to opening the connection or the recordset.

dbConn.CursorLocation = adUseClient

Hope this helps you. I have always ignored the databound controls and methods and have manually loaded and updated records when needed because it gives me greater control.

Upvotes: 1

Related Questions