li chen

li chen

  • NA
  • 1
  • 4.4k

How to return ADO recordset from a C# dll to Excel VBA.

Aug 14 2014 9:39 PM
I am working on a small project to conver vba class into C# library.

The vba class is a sql database operation one, it connects to database by using ADODB.Connection, return data Recordset in VBA. 

Question is how do I return Recordset type in C# library?

public Recordset SqlExecuteQuery(string psSQL)
{
ADODB.Recordset loRs = new ADODB.Recordset();
try
{
loRs.Open(psSQL,conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
}
catch (Exception e)
{
throw new Exception("Error " + e.Message + " encountered when executing the following query :" + psSQL);
}
return loRs;
}



but it returns error message in vba. 
Error Arguments are of the wrong type, ar out of acceptable range, or are in conflict with one another. encountered when executing the following query: select * from tb*****


Dim loRS As ADODB.Recordset
Set loRS = goDB.SqlExecuteQuery(psSQL)


Answers (1)