good ways to use recordsets without autocommit?

good ways to use recordsets without autocommit?

Post by Michael Hannema » Wed, 03 Dec 1997 04:00:00



The short form of the question is, "How do I create an updatable recordset
and limit it such that it only updates the database when I tell it to?"

This should be a fairly simple thing in principle, but going through online
help and various books, it seems completely impossible.  The Microsoft tech
note (<http://premium.microsoft.com/support/kb/articles/q172/3/81.asp>) on
VB Data controls and paused commitment looks promising, but I want to be
able to do this with recordsets I create and attach to generic ODBC
databases.  Normally when you open a recordset, it's either completely
unchangeable or automatically updating.  Where's the happy middle ground?

I'm also wondering how I can use the spiffy databound controls with any
ODBC database I choose -- how do you bind the Data control when you can't
set .database to a database you've opened? -- but I imagine I'll figure
that out.  Is there a particular reason why the language makes this
difficult to do?

Emailed responses are better than posts, but I'll come back and check
periodically.  Advice would be much appreciated.

Michael
--


 
 
 

good ways to use recordsets without autocommit?

Post by Euan deKoc » Thu, 04 Dec 1997 04:00:00


Hi,

I am not too sure here...

With RDO Resultsets you can open a resultset as rdconcurBatch.
Using this you can have a totally disassociated resultset. IE You can
actually disconnect the Database connection, continue with
Insert/Delete/Update operations and then reconnect and perform a
BatchUpdate which will send everything over.

This should be possible through a RecordSet. If it is not possible then use
RDO resultsets they are much more flexible.

Hope this helps.
--
Euan deKock
Gekko Services (Pvt) Ltd



Quote:> The short form of the question is, "How do I create an updatable
recordset
> and limit it such that it only updates the database when I tell it to?"


 
 
 

good ways to use recordsets without autocommit?

Post by Michael Hannema » Fri, 05 Dec 1997 04:00:00




>> The short form of the question is, "How do I create an updatable recordset
>> and limit it such that it only updates the database when I tell it to?"

>I ended up abandoning the Data control for this reason, among others. In
>contrast, you have complete control over the transaction commits and
>rollbacks if you use Recordset objects and OpenRecordset. There's more
>work involved, but it's possible to do it generically even in VB3. It
>should be even easier to do it with VB4 and VB5's ability to create OLE
>and ActiveX components.


suggested doing something involving opening the recordset a batch mode had
the right idea.  (In short, make sure the workspace DefaultCursorDriver is
dbUseClientBatchCursor, the recordset is opened with the dbOptimisticBatch
option, and then updates affect the local recordset, update dbUpdateBatch
commits to the database.)  It doesn't behave exactly like I'd expect --
other recordsets opened in dynaset batch mode don't have records
automatically modified upon database commit -- but it seems difficult to
have both batch updating and automatic data refresh, so I'm fine with that.

But now, I just want to know why Visual Basic (5.0, Enterprise ed.) crashes
_every time_ I open up a second project.  Whether I explicitly close the
first one or not, whether or not I open it via the 'Existing...' menu or
locate the file manually, whatever.  It gives me the by-now charming
message:

         Instruction at "0x0052de99" referenced memory at "0x00000000".
         The memory could not be "read".  

And, of course, it's terminate or debug from there.

It's always the same memory address, and it always tries to dereference
null.  And installing the Dev Studio service pack 3 did nothing to solve
it, sadly enough.  Has any one had this problem?

Michael
--


 
 
 

good ways to use recordsets without autocommit?

Post by Craig Lun » Fri, 05 Dec 1997 04:00:00



> I'm also wondering how I can use the spiffy databound controls with any
> ODBC database I choose -- how do you bind the Data control when you can't
> set .database to a database you've opened? -- but I imagine I'll figure
> that out.  Is there a particular reason why the language makes this
> difficult to do?

Just set the Recordset property only, the database property of datactl
will reflect the proper database.

At design time:
1)Place text box on form (Text1)
1)Place a datactl (Data1) on the form. Don't set any properties.
2)Link the (Text1) boundctl's "DataSource" property to the
datactl(Data1).

At runtime:

'Basically do this
'Open your database.
'Open your recordset of interest from that database.
'set data1.recordset=yourrecordset
'let yourctl.DataField="FieldNameToBindTo"
'clean up at end

Quote:>>>>>>>>>>>> EXAMPLE >>>>>>>>>>>>>>>>>>>>>>>>>

Dim db As Database  'Global
Dim rs As Recordset 'Global

Private Sub Form_Load()
        Set db = DBEngine.Workspaces(0).OpenDatabase("c:\mydbase.mdb")
        Set rs = db.OpenRecordset("myTableOrSQLstatement")
        Text1.DataField = "MyFieldName" 'Or whatever bound control
        Set Data1.Recordset = rs
End Sub

Private Sub Form_Unload(Cancel As Integer)
        Set Data1.Recordset = Nothing
        rs.Close
        db.Close
        Set rs = Nothing
        Set db = Nothing
End Sub

Have fun!

Craig Luna