VSTO (Access) – How to return a RecordSet from a OleDb Provider?
// ----------------------------------------------------------------------------------------
// Author: Joao Tito Livio
// Company: MACL
// Assembly version: 0.0.*
// Date: 21-04-2009
// Time: 23:55
// Project Item Name: M3Data.cs
// Project Item Filename: M3Data.cs
// Project Item Kind: Code
// Class FullName: Macl.M3Data
// Class Name: M3Data
// Class Kind Description: Class
// Class Kind Keyword: class
// Procedure FullName: Macl.M3Data.ReturnRecordset
// Procedure Name: ReturnRecordset
// Procedure Kind Description: Function
// Procedure Kind Keyword:
// Function Return Type Name: Recordset
// Function Return Type FullName: ADODB.Recordset
// Function Return Type Alias: Recordset
// Purpose: Return a recordset from any OleDb provider
// Parameters:
// - MyConnectionString (string)() : Connection strin for the OleDb Conenction
// - MyTableOrSQL (string)() : Can be a Table or a SQL statement
// - MyCursorType (CursorTypeEnum)() : http://msdn.microsoft.com/en-us/library/ms677593(VS.85).aspx
// ----------------------------------------------------------------------------------------
public ADODB.Recordset ReturnRecordset(String MyConnectionString, String MyTableOrSQL,
ADODB.CursorTypeEnum MyCursorType)
{
ADODB.Connection cnn = new ADODB.Connection();
ADODB.Recordset rs = new ADODB.Recordset();
try
{
cnn.ConnectionString = MyConnectionString;
cnn.Open(null, null, null, 0);
//}
rs.Open(MyTableOrSQL, cnn, MyCursorType, ADODB.LockTypeEnum.adLockOptimistic, -1);
return rs;
}
catch (Exception)
{
throw;
}
}