Write data from worksheet into recordset.
int WriteRecordset( Object & object, DWORD dwCntrl = LAYWKSETRECORDSET_REPLACE, int nRowBegin = 0, int nNumRows = -1, int nColBegin = 0, int nNumCols = -1 )
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" // when bReplace is true, it will delete all entry firstly then copy data from current worksheet to table. // NOTE if you wants to use append, and there is a Key field which not allow duplicate data, then you have to make sure after appending no duplicate data in key field/column. int WriteRecordset_ex1(bool bReplace = TRUE) { Worksheet wks = Project.ActiveLayer(); if(!wks) { // assume use active wks out_str("NO active wks!"); return -1; } Object ocrs; ocrs = CreateObject("ADODB.Recordset"); if( !ocrs ) { out_str(" ADO init error!"); return -1; } // Get Access file name string strDBFileName = DB_FILE_FULLPATH; if ( !strDBFileName.IsFile() ) { out_str("Invalid database file path!"); return -1; } // prepare and open database recordset string strConn = DB_SETUP_STR + strDBFileName; ocrs.CursorLocation = 3; string strQuery = "Select * From "+ TABLE_NAME + ";"; ocrs.open( strQuery, strConn, 0, 3); int nOption = LAYWKSETRECORDSET_APPEND; if ( bReplace ) nOption = LAYWKSETRECORDSET_REPLACE; //write worksheet data to recordset. int nRet = wks.WriteRecordset(ocrs,nOption ); out_int("nRet = ", nRet); if ( nRet ) return nRet; if (ocrs.State == 1 ) //adStateOpen ocrs.Close(); return 0; }
Worksheet::ReadRecordset, Worksheet::PutRecordset
origin.h