CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Building Interactive UIs with ASP.NET Ajax: Rebinding Client-Side Events After a Partial Page Postback
  • Speed Up Repetitive Insert, Update, and Delete Query Statements
  • Binding Data to Silverlight 4.0 Controls Using ASP.NET MVC Framework 2.0
  • ADO.NET Data Services in the .NET Framework

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old April 3rd, 2009, 02:43 AM
    shong shong is offline
    Junior Member
     
    Join Date: Apr 2009
    Posts: 2
    shong is an unknown quantity at this point (<10)
    Exclamation ADO VC++ Stored procedure problem.

    ok this a have this problem thats bugging me for 2 weeks and i couldn't find a solution to this.
    hopefully someone can enlighten me. Thanks in advance!

    the story goes :

    i have written a MFC to call on a few stored procedures i have in SQL server.

    the 1st sp
    CREATE PROCEDURE sp_Remove_Particulars
    (
    @student_ID int
    )
    as
    begin

    Delete from App_Student
    where ID = @student_ID

    Delete from Sys_Student_Subject
    where student_subject_ID = @student_ID

    Delete from Sys_Student_Class
    where Student_Class_ID = @student_ID

    end

    2nd sp

    CREATE PROCEDURE sp_Edit_Particulars
    (
    @Student_ID int,
    @cClass char(1)
    )
    as
    begin ( and so on..)

    the command codes in VC++ :

    the program can successfully call on the 1st sp but fails for the second one
    (i suspect its smthing to do with the

    void CADOMFC1View::OnMenuitem32772()
    {
    _CommandPtr pCommand;
    pCommand.CreateInstance(__uuidof( Command ));
    CADOMFC1Doc * pDoc;
    pDoc = GetDocument();
    try
    {
    pCommand->ActiveConnection = pDoc->m_pConnection;
    pCommand->CommandType = adCmdStoredProc;
    pCommand->CommandText = _bstr_t("sp_Remove_Particulars");

    VARIANT vIntegerType;
    vIntegerType.vt = VT_I2; //Variant type for Integer
    vIntegerType.intVal = 32;

    pCommand->Parameters->Append(pCommand->CreateParameter(_bstr_t("student_ID"),adInteger,adParamInput,4,vIntegerType));

    _variant_t vNull;
    vNull.vt = VT_ERROR;
    vNull.scode = DISP_E_PARAMNOTFOUND;

    pCommand->Execute(NULL,NULL,adCmdStoredProc);

    AfxMessageBox("Data Removed Successfully");
    }

    catch( _com_error &e )
    {
    TRACE( "Error:%08lx.\n", e.Error());
    TRACE( "ErrorMessage:%s.\n", e.ErrorMessage());
    TRACE( "Source:%s.\n", (LPCTSTR) _bstr_t(e.Source()));
    TRACE( "Description:%s.\n", (LPCTSTR) _bstr_t(e.Description()));
    }

    catch(...)
    {
    TRACE( "\n*** Unhandled Exception ***\n" );
    }
    }

    void CADOMFC1View::OnMenuitem32773()
    {
    _CommandPtr pCommand;
    pCommand.CreateInstance(__uuidof( Command ));
    CADOMFC1Doc * pDoc;
    pDoc = GetDocument();
    try
    {
    pCommand->ActiveConnection = pDoc->m_pConnection;
    pCommand->CommandType = adCmdStoredProc;
    pCommand->CommandText = _bstr_t("sp_Edit_Particulars");

    VARIANT vInteger;
    vInteger.vt = VT_I2; //Variant type for Integer
    vInteger.intVal = 33;

    VARIANT cClass;
    cClass.vt = VT_BSTR; //Variant type for BSTR
    cClass.bstrVal = _bstr_t("Class");

    pCommand->Parameters->Append(pCommand->CreateParameter(_bstr_t("Student_ID"),adInteger,adParamInput,4,vInteger)); pCommand->Parameters->Append(pCommand->CreateParameter(_bstr_t("cClass"),adChar,adParamInput,2,cClass));

    _variant_t vNull;
    vNull.vt = VT_ERROR;
    vNull.scode = DISP_E_PARAMNOTFOUND;

    pCommand->Execute(NULL,NULL,adCmdStoredProc);

    AfxMessageBox("Data Edited Successfully");
    }

    catch( _com_error &e )
    {
    TRACE( "Error:%08lx.\n", e.Error());
    TRACE( "ErrorMessage:%s.\n", e.ErrorMessage());
    TRACE( "Source:%s.\n", (LPCTSTR) _bstr_t(e.Source()));
    TRACE( "Description:%s.\n", (LPCTSTR) _bstr_t(e.Description()));
    }

    catch(...)
    {
    TRACE( "\n*** Unhandled Exception ***\n" );
    // TRACE(e.Description());
    }

    }

    as u can see the 1st sp calls for one "input" namely the ID
    but the second one calls for two inputs.
    i tried using variant type for char but i didnt worked so i kept to BSTR.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:31 AM.



    Acceptable Use Policy

    Internet.com
    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.