Read data from recordset object into worksheet.
int ReadRecordset( Object & object, DWORD dwCntrl = LAYWKGETRECORDSET_BY_COLUMN_INDEX_WITH_COLUMN_RENAMING, int nRowBegin = 0, int nNumRows = -1, int nColBegin = 0, POSTREADRS postReadRS = NULL )
error message, 0 if no error
EX1
#define DB_SETUP_STR "Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=Admin;Data Source=" #define DB_FILE_FULLPATH GetAppPath(TRUE) + "Samples\Import and Export\stars.mdb" #define TABLE_NAME "Stars" //function to retrieve data and put into a worksheet int ReadRecordset_ex1() { //create the ADODB.Recorset object Object ocrs = CreateObject("ADODB.Recordset"); if( !ocrs ) { out_str(" ADO init error!"); return -1; } // prepare and open database recordset string strConn = DB_SETUP_STR + DB_FILE_FULLPATH + ";"; string strQuery = "select * from "+ TABLE_NAME + ";"; //make the recordset ReadOnly (adUseClient) for faster open ocrs.CursorLocation = 3;//3=adUseClient(enum added in Origin 9) ocrs.open(strQuery, strConn, 1, 3); //prepare worksheet Worksheet wks; wks.Create("origin"); //read data into the worksheet. int nRet = wks.ReadRecordset(ocrs); if ( nRet ) return nRet; if (ocrs.State == 1 ) //adStateOpen ocrs.Close(); return 0; }
The performance depends on how the recordset is opened, as controlled by CursorLocation (adUseClient, or adUseServer, see in query_utils.h). For reading into worksheet, usually set CursorLocation as adUseCient is enough, which will cause CursorType be set as adOpenStatic, which means that any other application's update into source database will not affect this recordset once it is open. It is like the recordset is open as read-only. See CursorType, CursorLocation for more details.
Worksheet::WriteRecordset | Worksheet::PutRecordset
origin.h