|
-
Jan 16th, 2008, 05:44 AM
#1
Thread Starter
PowerPoster
[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
-
Jan 17th, 2008, 02:54 AM
#2
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|