Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 634457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:17:53+00:00 2026-05-13T20:17:53+00:00

Here is the code. A Few notes about it. DStr is an string class

  • 0

Here is the code.
A Few notes about it. DStr is an string class that is internal to our company. It functions much like CString. I can connect to the database and run non-parameterized queries. Also this insert works fine if I do not use parameters. The cmd->Execute statment throws an exception. This is where I am getting the error msg from.

    void CEmailArchiveDatabase::TestAddUser( DStr username, DStr displayname )
{

    DStr sql = "INSERT INTO [User] (UserName, DisplayName) VALUES (@Param1, @Param2)";

    _variant_t vUser;
    _variant_t vDisp; 

    vUser.vt = VT_BSTR;
    vUser.bstrVal = username.AllocSysString();
    vDisp.vt = VT_BSTR;
    vDisp.bstrVal = displayname.AllocSysString();

    _CommandPtr cmd = NULL;
    _ConnectionPtr conn = NULL;
    _ParameterPtr prm = NULL;

    DStr connStr = "driver={SQL Server};server=DEMETER\\SQLEXPRESS;database=ExtractoMundo";

    try
    {
        conn.CreateInstance(__uuidof(Connection));
        cmd.CreateInstance(__uuidof(Command));

        if( !(conn->GetState() & adStateOpen) )
        {
            conn->ConnectionString = connStr.AllocSysString();
            conn->Open("", "", "", NULL);
            conn->CursorLocation = adUseClient;
        }   

        cmd->ActiveConnection = conn;
        cmd->CommandText = sql.AllocSysString();
        cmd->CommandType = adCmdText;

        prm = cmd->CreateParameter("@Param1", adLongVarChar, adParamInput, -1, vUser);
        cmd->Parameters->Append(prm);
        prm = cmd->CreateParameter("@Param2", adLongVarChar, adParamInput, -1, vDisp);
        cmd->Parameters->Append(prm);

        _variant_t recAff;

        cmd->Execute(&recAff, NULL, adExecuteNoRecords);

    }
    catch(_com_error &ex)
    {
        //ClearParameters();
        DStr err;
        err += PrintProviderError(conn);
        err += PrintComError(ex);
    }

    SysFreeString(vUser.bstrVal);
    SysFreeString(vDisp.bstrVal);
    SysFreeString(cmd->CommandText);
    SysFreeString(conn->ConnectionString);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:17:53+00:00Added an answer on May 13, 2026 at 8:17 pm

    ADO refuses to work with named parameters in dynamic queries. You have to either convert named parameters into parameter placeholders:

    DStr sql = "INSERT INTO [User] (UserName, DisplayName) VALUES (?, ?)";
    

    or use a stored procedure instead. Create the procedure:

    CREATE PROCEDURE spUserInsert
      @Param1 nvarchar(50), 
      @Param2 nvarchar(50) 
    AS 
      SET NOCOUNT ON;
      INSERT INTO [User] (UserName, DisplayName) VALUES (@Param1, @Param2)
    GO
    

    and modify your code to call it:

    DStr sql = "spUserInsert";
    ...
    cmd->CommandType = adCmdStoredProcedure;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 315k
  • Answers 315k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A ref parameter: has to be initialized by the caller.… May 13, 2026 at 11:18 pm
  • Editorial Team
    Editorial Team added an answer this has to do with structure packing. by adding the… May 13, 2026 at 11:18 pm
  • Editorial Team
    Editorial Team added an answer Yep, that's exactly what macros do. Here's a straightforward macro… May 13, 2026 at 11:18 pm

Related Questions

I started with Turbo Pascal 3, went to TP5, Bought TP6 called Borland the
I'm not a Notes programmer, however, for my sins, have been working on some
Lately as part of my day job I've been learning IBM Rhapsody and using
UPDATE As Mathias notes below, this exact problem has been reported and resolved here:
I've been trying to migrate a fairly large web application from IIS6 to IIS7

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.