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

  • SEARCH
  • Home
  • 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 7003755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:06:36+00:00 2026-05-27T21:06:36+00:00

Below is the insert function in VC++. I am getting this error when I

  • 0

Below is the insert function in VC++.
I am getting this error when I change the char to string data type to read the value of amount variable in the below code.

static void Insert(t_analysis* analysis)    
{    
 _bstr_t strunitId;    
 _bstr_t strGdt=time(0);    
_bstr_t strvalue;   
    std::string str;
std::string commandStr = "insert into table1(unitid,g_time_dte_1,h_1,n_1,ch_1,co_1,im_1,ve_1,er_1) Values(123,'" + strGdt +"',";
    char tempBuf[50];
for (int j = 0; j < analysis->ubPeaksIntTab;j++ )
{   
    sprintf(tempBuf, "%d", (analysis->peak + j)->amount);//here it takes the adrress of amount but not the value of amount variable.
    str += commandStr + tempBuf;
    if(j!=analysis->ubPeaksIntTab-1)
       commandStr += ",";
}

commandStr += ")";
_ConnectionPtr pConn = NULL;

try
{       
    HRESULT hr = S_OK;
    CoInitialize(NULL);
    hr = pConn.CreateInstance((__uuidof(Connection)));
    _bstr_t strCon("Provider=SQLOLEDB;Dataq Source=MYPC\\SQLEXPRESS;Initial Catalog=keerth;User ID=sa;Password=password;Connect Timeout=30;");

    if(FAILED(hr))
    {
        printf("Error instantiating Connection object\n");

    }

    hr = pConn->Open(strCon,"sa","password",0);

    if(FAILED(hr))
    {
        printf("Error Opening Database object using ADO _ConnectionPtr \n");

    }

    //Execute the insert statement
    pConn->Execute(commandStr.c_str(), NULL,adExecuteNoRecords);
    pConn->Close();
}
catch(_com_error &ce)
{
    printf("Error:%s\n",ce.ErrorMessage());
    pConn->Close();
}
}

Whenever I run this getting the Error. Then I changed the char tempbuf[50]; to std::string str1;.
Now it is showing:

Error C2664: 'sprintf' : cannot convert parameter 1 from 'std::string' to 'char *;

The amount variable contains the float value.
How can I copy the float value assign it to string variable?

  • 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-27T21:06:37+00:00Added an answer on May 27, 2026 at 9:06 pm

    You are mixing C++ with C standard library functions.

    You should use the C++ primitives. See StringStreams

    #include <iostream>
    #include <string>
    #include <sstream>
    
    int main () {
      std::stringstream ss;
      ss << "hello world";
      ss << 45;
      ss << std::endl;
      std::string foo = ss.str();
      std::cout << foo;
      return 0;
    }
    

    EDIT:

    If you want the same logic in C: The type std::string is not a C type, the standard string type of C is char * and const char * for immutable strings.

    The functions that you want to look at are then: strncat (concatenate strings) and the safer snprintf.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my current char* to hex string function. I wrote it as an
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
The trigger below is delaying my insert response. How can I prevent this? create
The function below, as its name suggests, registers/records the data from signup form into
I am new to jquery ! I am using the code below to insert
I have below code to insert a style into DOM (there is a use
I have a query like below declare @str_CustomerID int Insert into IMDECONP38.[Customer].dbo.CustomerMaster ( CustomerName
I have a byte array highlighted below, how do I insert it into a
I have the jQuery function below which alters the CSS on hover of a
I'm trying to use a function with PostgreSQL to save some data. Here is

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.