Matt - More ADO/EuCom questions
- Posted by Jonas Temple <jtemple at yhti.net> Oct 28, 2004
- 525 views
Matt, Sorry to keep coming back, but since few EuCom examples exist using ADO, I don't know where else to turn... <dramatic scene> Matt: Jonas, I'm going to recommend you be removed from the program. Jonas: No, you can't do that! I aint got nowhere else to go! Jonas sobs, sitting in the puddle of mud. </dramatic scene> My ADO program is working SO FAR and now I'm trying to actually get data from one of the columns in a record set. The problem I'm running into is trying to retrieve the a Field object from the Fields object. The following code generates the following message when trying to get a Field_p_Item property from ado_fields: 80020009: Exception occurred. Exception Source: ADODB.Fields Exception Description: Item cannot be found in the collection corresponding to t he requested name or ordinal. I noticed that the ordinal for Fields_p_Item property in msado27.ew is 0? Thanks again for your help!
with trace without warning include eucom.ew include msado27.ew atom ado_connect, void, conn_str, cmd_str, ado_rcdset, rtn_val, ado_fields, ado_field, ado_variant sequence text com_err_out(1) ado_connect = create_com_object(Connection_clsid_ix) --ado_rcdset = create_com_object(Recordset_clsid_ix) -- Event functions for ConnectionEvents procedure ConnectionEvents_InfoMessage_proc( atom this, atom pError, atom adStatus, atom pConnection ) puts(1,"InfoMessage\n") end procedure com_event_routine( ado_connect, ConnectionEvents_InfoMessage, routine_id("ConnectionEvents_InfoMessage_proc" )) procedure ConnectionEvents_BeginTransComplete_proc( atom this, atom TransactionLevel, atom pError, atom adStatus, atom pConnection ) puts(1,"BeginTransComplete\n") end procedure com_event_routine( ado_connect, ConnectionEvents_BeginTransComplete, routine_id("ConnectionEvents_BeginTransComplete_proc" )) procedure ConnectionEvents_CommitTransComplete_proc( atom this, atom pError, atom adStatus, atom pConnection ) puts(1,"CommitTransComplete\n") end procedure com_event_routine( ado_connect, ConnectionEvents_CommitTransComplete, routine_id("ConnectionEvents_CommitTransComplete_proc" )) procedure ConnectionEvents_RollbackTransComplete_proc( atom this, atom pError, atom adStatus, atom pConnection ) puts(1,"RollbackTransComplete\n") end procedure com_event_routine( ado_connect, ConnectionEvents_RollbackTransComplete, routine_id("ConnectionEvents_RollbackTransComplete_proc" )) procedure ConnectionEvents_WillExecute_proc( atom this, atom Source, atom CursorType, atom LockType, atom Options, atom adStatus, atom pCommand, atom pRecordset, atom pConnection ) puts(1,"WillExecute\n") end procedure com_event_routine( ado_connect, ConnectionEvents_WillExecute, routine_id("ConnectionEvents_WillExecute_proc" )) procedure ConnectionEvents_ExecuteComplete_proc( atom this, atom RecordsAffected, atom pError, atom adStatus, atom pCommand, atom pRecordset, atom pConnection ) puts(1,"ExecuteComplete\n") end procedure com_event_routine( ado_connect, ConnectionEvents_WillConnect, routine_id("ConnectionEvents_ExecuteComplete_proc" )) procedure ConnectionEvents_WillConnect_proc( atom this, atom ConnectionString, atom UserID, atom Password, atom Options, atom adStatus, atom pConnection ) puts(1,"WillConnect\n") end procedure com_event_routine( ado_connect, ConnectionEvents_WillConnect, routine_id("ConnectionEvents_WillConnect_proc" )) procedure ConnectionEvents_ConnectComplete_proc( atom this, atom pError, atom adStatus, atom pConnection ) puts(1,"ConnectComplete\n") end procedure com_event_routine( ado_connect, ConnectionEvents_ConnectComplete, routine_id("ConnectionEvents_ConnectComplete_proc" )) procedure ConnectionEvents_Disconnect_proc( atom this, atom adStatus, atom pConnection ) puts(1,"Disconnect\n") end procedure com_event_routine( ado_connect, ConnectionEvents_Disconnect, routine_id("ConnectionEvents_Disconnect_proc" )) -- Start of real code conn_str = alloc_bstr("Provider=IBMDA400;Data Source=66.140.221.246") -- This connect approach works --void = invoke( ado_connect, {Connection_p_ConnectionString}, {conn_str}, {VT_BSTR}, DISPATCH_PROPERTYPUT ) --void = invoke(ado_connect, {"Open"},{},{},DISPATCH_METHOD) -- So does this one void = invoke(ado_connect, {Connection_m_Open},{conn_str},{VT_BSTR},DISPATCH_METHOD) -- Print the connected state, should be a 1 ? invoke(ado_connect, {"State"}, {},{}, DISPATCH_PROPERTYGET ) void = wait_key() -- Now try just executing a command cmd_str = alloc_bstr("{CALL QSYS.QCMDEXC('SNDMSG MSG(''TEST FROM ADO'') TOUSR(JONAS)',0000000040.00000)}") void = invoke(ado_connect, {Connection_m_Execute},{cmd_str},{VT_BSTR},DISPATCH_METHOD) free(cmd_str) -- Now we'll try retrieving some records cmd_str = alloc_bstr("select * from qgpl.qauoopt") rtn_val = invoke(ado_connect, {Connection_m_Execute},{cmd_str},{VT_BSTR},DISPATCH_METHOD) ado_rcdset = ref_com_object(Recordset_clsid_ix,rtn_val) ? invoke(ado_rcdset,{Recordset_p_RecordCount},{},{},DISPATCH_PROPERTYGET ) -- Maybe print the first record? rtn_val = invoke(ado_rcdset,{Recordset_p_Fields},{},{},DISPATCH_PROPERTYGET ) ado_fields = ref_com_object(Fields_clsid_ix,rtn_val) trace(1) ? invoke(ado_fields,{Fields_p_Count},{},{},DISPATCH_PROPERTYGET ) rtn_val = invoke(ado_fields,{Fields_p_Item},{0},{VT_VARIANT},DISPATCH_PROPERTYGET ) ado_field = ref_com_object(Field_clsid_ix,rtn_val) rtn_val = invoke(ado_fields,{Field_p_Value},{},{},DISPATCH_PROPERTYGET ) text = get_variant(rtn_val) ? text void = invoke(ado_rcdset, {Recordset_m_Close},{},{},DISPATCH_METHOD) free(cmd_str) -- close the connection void = invoke(ado_connect, {Connection_m_Close},{},{},DISPATCH_METHOD) free(conn_str) void = wait_key() release_com()
Jonas Temple http://www.yhti.net/~jktemple