Results 1 to 2 of 2

Thread: [RESOLVED] Write values to a database within the C++ code

  1. #1

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Resolved [RESOLVED] Write values to a database within the C++ code

    Hi all,

    On a database I have a table, with two columns, named as FileName and the FileType. On the table I define the data type as 'Text'. I try to add some data to it within my code as follows.

    Code:
    	_RecordsetPtr pRec;
    	ostringstream sqlCmd;
    	char chState = 'R';
    
    	bool bState = true;	// Type handle, cmdline
    	if(bState)
    		chState = 'R';
    	else
    		chState = 'T';
    
    	sqlCmd << "INSERT INTO tblGroupState(DiskFileName, FileState) VALUES(" << fileName << ", "
    		<< chState << ")";
    
    	try
    	{
    		pRec = m_pConn->Execute(sqlCmd.str().c_str(), NULL, adCmdText);
    
    		pRec->Close();
    	}
    	catch(_com_error &e)
    	{
    		_bstr_t bstrSource(e.Source());
    		_bstr_t bstrDescription(e.Description());
    		printf("\n Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
    	}
    Here, m_pConn is the connection to the database and it is perfectly work. Because I used it previously.

    My code gives an error, Can you guys find that where I'm going wrong with.

    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  2. #2

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Write values to a database within the C++ code

    Time to mark SOLVED this tread. I solved it, made a mistake that manipulating the sql command string there.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width