Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating an ADODB recordset programmatically

I am attempting to generate an ADO RecordSet programmatically within .Net. This will be passed on to existing legacy code in VB6 which is already expecting a ADO RecordSet, I do not wish to change the existing code.

I was successful in defining fields within a new RecordSet

ADODB.Recordset rs = new Recordset();
            rs.Fields.Append("Height", DataTypeEnum.adInteger, 4, FieldAttributeEnum.adFldMayBeNull, null);

within VB6 I can add records after calling Open on the RecordSet with no parameters:

rs.Open

when I try to call AddNew with in .net code it tells me the recordset must be open, and I can't call open because it is expecting the following parameters:

void Open(object Source, object ActiveConnection, CursorTypeEnum CursorType, LockTypeEnum LockType, int Options);

but I am attempting to load the RecordSet programmatically and do not have any active connection or other datasource.

What am I missing? Is there a better way?

like image 472
benPearce Avatar asked Mar 29 '26 19:03

benPearce


1 Answers

Those parameters are all optional in the ADODB.Recordset.Open method. Try explicitly passing the default values as specified in the documentation. There is one parameter, Source, with no explicit default listed. I imagine the default is Nothing. EDIT I guessed wrong, apparently it is System.Type.Missing

So the solution is:

rs.Open (System.Type.Missing, System.Type.Missing, _
  adOpenUnspecified, adLockUnspecified, -1)
like image 116
MarkJ Avatar answered Apr 02 '26 07:04

MarkJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!