How insert new procedure in .mdb file? 
Author Message
 How insert new procedure in .mdb file?

Dear Sirs programmers, help me please.

I use MSDN example (ADOX) for updating text of procedure in .mdb file.
All work fine, but when I want to insert new procedure in .mdb file,
new procedure does not create. How change this code for creating
procedure(inquiry or query):

        //Update the CommandText
        m_pCommand->PutCommandText("PARAMETERS [CustId] Text;select "
            "CustomerId, CompanyName, ContactName "
            "from Customers where CustomerId = [CustId]");

        //Update the Procedure
        m_pCatalog->Procedures->GetItem("CustomerById")->PutCommand(
            _variant_t((IDispatch *)m_pCommand));

Maybe?
        m_pCatalog->Procedures->Append("MyProcedure",
_variant_t((IDispatch *)m_pCommand));

but no results from this instruction.

Command and CommandText Properties Example (VC++)
The following code demonstrates how to use the Command property to
update the text of a procedure.
// BeginCommandTextCpp
#import "c:\Program Files\Common Files\system\ado\msadox.dll" \
    no_namespace
#import "c:\Program Files\Common Files\system\ado\msado15.dll"

#include "iostream.h"
#include "stdio.h"
#include "conio.h"

//Function declarations
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
void ProcedureTextX(void);

//////////////////////////////////////////////////////////
//                                                      //
//      Main Function                                   //
//                                                      //
//////////////////////////////////////////////////////////
void main()
{
    if(FAILED(::CoInitialize(NULL)))
        return;

    ProcedureTextX();

    ::CoUninitialize();

Quote:
}

//////////////////////////////////////////////////////////
//                                                      //
//       ProcedureTextX Function                        //
//                                                      //
//////////////////////////////////////////////////////////
void ProcedureTextX()
{
    HRESULT hr = S_OK;

    // Define ADOX object pointers.
    // Initialize pointers on define.
    // These are in the ADOX::  namespace.
    _CatalogPtr m_pCatalog = NULL;

    // Define ADODB object pointers.
    ADODB::_ConnectionPtr m_pCnn = NULL;
    ADODB::_CommandPtr m_pCommand = NULL;

    try
    {
        //Open the Connection
        TESTHR(hr = m_pCnn.CreateInstance(__uuidof(ADODB::Connection)));
        TESTHR(hr = m_pCatalog.CreateInstance(__uuidof(Catalog)));
        TESTHR(hr = m_pCommand.CreateInstance(__uuidof(ADODB::Command)));
        m_pCnn->Open("Provider=Microsoft.Jet.OLEDB.4.0;"
            "data source=c:\\Program Files\\Microsoft Office"
            "\\Office\\Samples\\Northwind.mdb;","","",NULL);

        //Open the catalog
        m_pCatalog->PutActiveConnection(_variant_t((IDispatch
*)m_pCnn));

        //Get the Command
        m_pCommand =
m_pCatalog->Procedures->GetItem("CustomerById")->GetCommand();

        //Update the CommandText
        m_pCommand->PutCommandText("PARAMETERS [CustId] Text;select "
            "CustomerId, CompanyName, ContactName "
            "from Customers where CustomerId = [CustId]");

        //Update the Procedure
        m_pCatalog->Procedures->GetItem("CustomerById")->PutCommand(
            _variant_t((IDispatch *)m_pCommand));
    }

    catch(_com_error &e)
    {
        // Notify the user of errors if any.
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());

        printf("\n\tSource :  %s \n\tdescription : %s \n
",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
    }

    catch(...)
    {
        cout << "Error occured in include files...."<< endl;
    }

Quote:
}

// EndCommandTextCpp
See Also
Command Property

Thank in advance.



Sun, 31 Oct 2004 14:39:43 GMT  
 How insert new procedure in .mdb file?
I solve my problem with my database.

Must be:
                m_pCnn->Open("Provider=Microsoft.Jet.OLEDB.4.0;data
source=C:\\Ax970011\\MDB\\ax970011.mdb;jet oledb:System
Database=c:\\AX970011\\Ax970011.mdw;User Id=Admin","","",NULL);

All work fine!



Mon, 01 Nov 2004 11:26:48 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. new file (MDB)

2. How to create a new Access(.mdb) file with VC++

3. WTL - Very new to WTL - Trying to insert new COM object in WTL

4. Insert Using Stored Procedure

5. INSERT/UPDATE stored procedure

6. Window procedure, window class procedure and dialog procedure

7. How to create new mdb with ADO

8. How to transform a mdb file into a xls file

9. *.MDB file open exception???(Unrecognized file format...)

10. create a new .mdb database with ado?

11. Creating a new .mdb database under program control...

12. synchronize the MDB file with CDB file using Activesync

 

 
Powered by phpBB® Forum Software