Ado 2.7 Download
Install ADO 2.8, get ADO 2.7? Microsoft Access / VBA Forums on Bytes. Dec 20, 2016 Download ADOdb for free. PHP database abstraction layer. ADOdb is a PHP database class library to provide more powerful abstractions for performing queries.
Ok, this has completely stumped me. Here's the deal. I have a VB6 DLL that I have registered as a COM, and have also created a.NET wrapper for using tlbimp.exe. I have also included a wrapper for msado15.dll, the ADO 2.7 Microsoft DLL containing the ADODB._Recordset and ADODB._Record references. Additionally, that is the EXACT (and only) DLL I am referencing in VB6 and using for my recordets. I am not sure if its DLL mismatch problem. When you are returning string, it seems to be working because.Net framework is going to call ToString method on the returned object.
Return value being a string, it works ok. Now when you are returning a RS as a varaint, for.Net its going to a generic 'object' type. Try the folowing 2 things.
Object ob = objIADB.Query_DB('MAIN','G ROUPS',', 'GroupID', 'Asc','); And see ifwhat you get back. If the above suggestion works then try the following. Dim rsGroups as ADODB._Recordset = ADODB._Recordset (objIADB.Query_DB('MAIN',' GROUPS',','GroupID','Asc',') ); Sorry about C# code.
Did you use the tlbimp to generate your RCWs or did you use the VS.NET add reference capability? VS.NET uses some tlbimp switches that may be relevant specifically to ADO in order to correctly generate the wrapper, and I would remove and add the references for your project through that functionality, if you haven't already. To do this, go to your project references and remove the current ADODB reference, then go into References->Add Reference, go to the COM tab, and select Microsoft ActiveX Data Objects 2.7 Library. I suggest you do the same for all of your RCWs unless you have special marshalling requirements for your COM objects. Well, I feel like I am grasping at straws, but would you try: Dim rsGroups as ADODB.Recordset = CType(objIADB.Query_DB('MA IN','GROUP S',','Gro upID','Asc ','),ADOD B.Recordse t) or Dim rsGroups as ADODB.Recordset = DirectCast(objIADB.Query_D B('MAIN',' GROUPS',','GroupID','Asc','),ADODB.Rec ordset) -------------------------- - Also, as another attempt, try Dim rsGroups as Object = objIADB.Query_DB('MAIN','G ROUPS',', 'GroupID', 'Asc',') and set a breakpoint after the call. Create a watch on rsGroups, and tell me what type.NET thinks is being returned. Minchagi Neenu Baralu Instrumental.
This may be a clue into why there is an invalid cast. Well, I was working on the wrong thing this whole time. I thought you were having trouble getting the recordset back, and in my troubleshooting, I created a sample project which worked great. Hence my confusion. I tried to add the Fill code, just as you did, but instead of getting an InvalidCastException, I was getting 'Object is not an ADODB.Recordset or ADODB.Record.'
I fiddled a little, then found that when I changed the return parameter from Variant to ADODB.Recordset in the VB project, everything works like a charm. Nedeljni Program Za Sklekove. I suspect that you will have to modify the marshalling of the variant to change its type depending on the actual return value.
Examples of changing the marshalling that I have seen all refer to modifying the IL using ILDASM and recompiling. Personally, I think you would be better served to simply return a recordset that contains a single field which you could do by changing your select to: If Len(FieldName)>0 Then strSQL = 'Select ' & FieldName & ' from [' & Table & '] ' & ParamString Else strSQL = 'Select * from [' & Table & '] ' & ParamString End if I do not believe 'multifunction' functions should be used, in general. They do not follow Microsoft's guideline in that a function should accomplish a single, directed task. That is why the ADO.NET Command has ExecuteReader, ExecuteScalar, and ExecuteNonQuery. Instead of switching your functionality based on the FieldName if you want a single value returned, create two methods, one that will return a Scalar value (your FieldName) and one that will return a recordset.