Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2005-05-14
3
Medium Priority
?
347 Views
Last Modified: 2013-11-20
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??
0
Comment
Question by:shurid
3 Comments
 
LVL 6

Expert Comment

by:nabehs
ID: 14008685
// get the source sql of the recordset

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


0
 
LVL 3

Accepted Solution

by:
NawalKishore1976 earned 520 total points
ID: 14008730
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
 
LVL 1

Author Comment

by:shurid
ID: 15576756
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question