por pepo el Mar Mar 04, 2008 7:04 am
Hola buenas. mi problema es el siguiente en la segunda Vuelta de while me da error con las variabes RS1. cual es la forma correcta de usar ADO. muchas gracias
- Código: Seleccionar todo
CString id_expediente,codigo,numero,anio,nombre,asunto,expediente,fecha,ultimo,usuario_externo;
CString sql;
//Se crea una instancia del recordset
_RecordsetPtr Rs(__uuidof(Recordset));
_RecordsetPtr Rs1(__uuidof(Recordset));
_RecordsetPtr Rs2(__uuidof(Recordset));
//se le asocia la conexión
Rs->PutRefActiveConnection(pAdoCone);
Rs1->PutRefActiveConnection(pAdoCone);
Rs2->PutRefActiveConnection(pAdoCone);
CString msgErr;
try
{
//armo una cadena de tipo _bstr_t con la sentencia SQL necesaria
sql.Format("SELECT distinct e.* FROM Expedientes e, Expedientes_Hist h WHERE e.id_expediente=h.id_expediente and e.FECHA between '%s' and '%s' and e.COD_ORGANIGRAMA =%s order by e.id_expediente",f1,f2,m_codigo);
_bstr_t bstrSql(sql);
//abro el recordset
Rs->Open(bstrSql,vtMissing,adOpenForwardOnly,adLockReadOnly,adCmdText);
while(!Rs->adoEOF) //mientras no sea fin de archivo...
{
id_expediente = (char*) (_bstr_t) Rs->Fields->GetItem("id_expediente")->Value;
sql.Format("SELECT MIN(ID_EXPEDIENTE_HIST) AS UltimoExp,ID_USUARIO_EXT FROM Expedientes_hist WHERE ID_EXPEDIENTE=%s group by ID_USUARIO_EXT",id_expediente);
AfxMessageBox(sql);
_bstr_t bstrSql1(sql);
//abro el recordset
Rs1->Open(bstrSql1,vtMissing,adOpenForwardOnly,adLockReadOnly,adCmdText);
//ultimo = (char*) (_bstr_t) Rs1->Fields->GetItem("UltimoExp")->Value;
usuario_externo = (char*) (_bstr_t) Rs1->Fields->GetItem("ID_USUARIO_EXT")->Value;
AfxMessageBox(usuario_externo);
if(usuario_externo=="0")
{
sql.Format("SELECT E.COD_ORGANIGRAMA, E.NUMERO,E.ANIO,A.NOMBRE AS INICIADOR,E.ASUNTO,e.fecha FROM ((EXPEDIENTE.EXPEDIENTES E INNER JOIN EXPEDIENTE.ARBOL A ON E.ID_INICIADOR = A.ID_OBJETO) INNER JOIN EXPEDIENTE.EXPEDIENTES_HIST EH ON EH.id_Expediente = E.Id_Expediente) INNER JOIN EXPEDIENTE.ARBOL AR ON EH.DESDE = AR.ID_OBJETO WHERE E.ID_EXPEDIENTE=%s AND EH.Id_Usuario_Ext =0 ",id_expediente);
_bstr_t bstrSql2(sql);
Rs2->Open(bstrSql2,vtMissing,adOpenForwardOnly,adLockReadOnly,adCmdText);
}
else
{
sql.Format("SELECT E.cod_organigrama, E.numero,E.anio,UE.NOMBRE AS INICIADOR,E.ASUNTO,e.fecha FROM ((EXPEDIENTE.EXPEDIENTES E INNER JOIN EXPEDIENTE.USUARIOS_EXT UE ON E.ID_INICIADOR = UE.ID_USER_EXT) INNER JOIN EXPEDIENTE.EXPEDIENTES_HIST EH ON EH.id_Expediente = E.Id_Expediente) INNER JOIN EXPEDIENTE.ARBOL AR ON EH.DESDE= AR.ID_OBJETO WHERE E.ID_EXPEDIENTE=%s ",id_expediente);
_bstr_t bstrSql2(sql);
Rs2->Open(bstrSql2,vtMissing,adOpenForwardOnly,adLockReadOnly,adCmdText);
}
AfxMessageBox("dsf");
//abro el recordset
codigo = (char*) (_bstr_t) Rs2->Fields->GetItem("cod_organigrama")->Value;
AfxMessageBox(codigo);
numero = (char*) (_bstr_t) Rs2->Fields->GetItem("numero")->Value;
AfxMessageBox(numero);
anio = (char*) (_bstr_t) Rs2->Fields->GetItem("anio")->Value;
AfxMessageBox(anio);
nombre = (char*) (_bstr_t) Rs2->Fields->GetItem("iniciador")->Value;
AfxMessageBox(nombre);
asunto = (char*) (_bstr_t) Rs2->Fields->GetItem("asunto")->Value;
AfxMessageBox(asunto);
fecha = (char*) (_bstr_t) Rs2->Fields->GetItem("fecha")->Value;
AfxMessageBox(fecha);
expediente=codigo+"-"+numero+"-"+anio;
//lo agrego a la lista
int i =m_lista.GetItemCount();
m_lista.InsertItem(i,expediente);
m_lista.SetItemText(i,1,nombre);
m_lista.SetItemText(i,2,asunto);
m_lista.SetItemText(i,3,fecha);
//paso al siguiente registro
Rs->MoveNext();
Rs1->Close();
Rs1.Release();
Rs2->Close();
Rs2.Release();
Rs1->PutRefActiveConnection(pAdoCone);
Rs2->PutRefActiveConnection(pAdoCone);
}
Rs->Close();
Rs.Release();
}
catch (_com_error& ce)
{
ver_com_error(ce);
}