how to get the SQL statement from which a recordset is created??

i am using ADO _RecordsetPtr and _ConnectionPtr to create recordset from SQL statement...
say i created a rsTemp from a SQL statement "select * from client"....

now i have that rsTemp.....how can i find that SQL statement from which rsTemp object is created???

sample code
----------------------
_ConnectionPtr m_Connection;
_RecordsetPtr m_Recordset;

CString strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=False; Data Source= 'c:\temp.mdb'";

HRESULT hr = m_Connection.CreateInstance(__uuidof(Connection));      
BSTR bstrDataSource = strConnection.AllocSysString();
m_Connection->Open((_bstr_t)bstrDataSource,"","",-1);

TESTHR(m_Recordset.CreateInstance(__uuidof(Recordset)));

CString strSQL = "Select * From Client"
m_Recordset->Open((_variant_t)(strSQL),m_Connection.GetInterfacePtr(),
                                                      adOpenKeyset,
                                                      adLockBatchOptimistic,
                                                      adCmdText);
----------------------
now my Question is ..... from that m_Recordset how can i get the base SQL statement from which this is created?? in this senario the ans will be "Select * From Client"......

but how??? to find out??
LVL 1
shuridAsked:
Who is Participating?
 
NawalKishore1976Commented:
Use The GetSource Function:

_ConnectionPtr  pConnection          = NULL;
   _RecordsetPtr  pRstTitles        = NULL;
   _RecordsetPtr  pRstPublishers      = NULL;
   _RecordsetPtr  pRstPublishersDirect    = NULL;
   _RecordsetPtr  pRstTitlesPublishers    = NULL;
   _CommandPtr     pCmdSQL          = NULL;

     try
    {
        // Open a connection.
        TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
        pConnection->Open (strCnn, "", "", adConnectUnspecified);

        // Open a recordset based on a command object.
        TESTHR(pCmdSQL.CreateInstance(__uuidof(Command)));
        pCmdSQL->ActiveConnection = pConnection;
        pCmdSQL->CommandText = strCmdSQL;
        pRstTitles = pCmdSQL->Execute(NULL,NULL,adCmdText);

        // Open a recordset based on a a table
        TESTHR(pRstPublishers.CreateInstance(__uuidof(Recordset)));
        pRstPublishers->Open ("publishers",
            _variant_t((IDispatch *) pConnection, true),
            adOpenForwardOnly, adLockReadOnly, adCmdTable);

        // Open a recordset based on a table
        TESTHR(pRstPublishersDirect.CreateInstance(
            __uuidof(Recordset)));
        pRstPublishersDirect->Open ("publishers",
            _variant_t((IDispatch *) pConnection, true),
            adOpenForwardOnly, adLockReadOnly, adCmdTableDirect);

        // Open a recordset based on a SQL string.
        TESTHR(pRstTitlesPublishers.CreateInstance(
            __uuidof(Recordset)));
        pRstTitlesPublishers->Open(strSQL,
            _variant_t((IDispatch *) pConnection, true),
            adOpenForwardOnly, adLockReadOnly, adCmdText);

        // Use the Source property to display the source of
        // each recordset.
        printf("rstTitles source: \n%s\n\n",
            (LPCSTR)(_bstr_t) pRstTitles->GetSource().bstrVal);
        printf("rstPublishers source: \n%s\n\n",
            (LPCSTR)(_bstr_t) pRstPublishers->GetSource().bstrVal);
        printf("rstPublishersDirect source: \n%s\n\n",
            (LPCSTR)(_bstr_t) pRstPublishersDirect->GetSource().bstrVal);
        printf("rstTitlesPublishers source: \n%s\n\n",
            (LPCSTR)(_bstr_t) pRstTitlesPublishers->GetSource().bstrVal);

0
 
nabehsCommented:
// get the source sql of the recordset

_variant_t  vSrc  = m_Recordset->GetSource();
CString strSQL = vSrc.bstrVal;


0
 
shuridAuthor Commented:
Sorry for my Acception Delay ... cos "NawalKishore1976" u gave me answer after 2days and by then i got the solution by my self and forget to close the Q... ur answer is right so i am giving u the point....and thankx a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.