Click here to Skip to main content
13,090,730 members (44,153 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want to add the value of my CString into the datbase i already created.

CString textvalue  = _T("DarkKnight");
const char *pSQL[1];
pSQL[0] = "insert into Movies (Title, Director, Year) values (''+textvalue+'', 'Nolan', 2008)";
int rc = sqlite3_exec(database, pSQL[0], callback, 0, &zErrMsg);

When i am executing the command i am getting an error message "There is no column by name textvalue in the database".

How do i insert the value "DarkKnight" into the SQLite database at runtime.
Posted 21-Jun-12 10:32am
Wes Aday 21-Jun-12 16:34pm
pSQL[0] = "insert into Movies (Title, Director, Year) values ('" + textvalue + "', 'Nolan', 2008)";

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Here's the code I use in a C++ cgi module.

sprintf(buffer, "INSERT INTO `cds` (title,artist,year) VALUES('%s','%s',%d)", bTitle.c_str(), bArtist.c_str(), yr);
queryStr = buffer;

At a guess, it looks like you've used mySql before in PHP from the way you expect to have the contents of the variable substituted for the variable name.

EDIT: something I whacked together in MFC:
void CmfcSqliteDlg::OnBnClickedButton1()
	CString queryStr;
	CString artStr, albStr, yrStr;
	artStr = _T("DeadMau5");
	albStr = _T("4x4 = 12");
	yrStr = _T("2010");
	queryStr.Format(L"insert into cds (title, artist, year) values('%s', '%s', %s)", artStr, albStr, yrStr);
	char *charStr = T2A(queryStr);
	MessageBox(queryStr, _T("Query to execute"));
	MessageBoxA(NULL, charStr, "Query to exeute", MB_OK);
Sandeep Mewara 22-Jun-12 1:53am
My 5!
amarasat 22-Jun-12 10:29am
Thanks alot for your help!! Both ways have worked!!

My 5 too!
amarasat 22-Jun-12 15:59pm
How do i solve this:

CString textvalue = _T("120");
CString Tag = _T("Plugin1@PLG.Value1@Value");
queryStr.Format(L"update Table set Value=%s where Tag=%s", textvalue, Tag);
char *pSQL[0] = T2A(queryStr);
int rc = sqlite3_exec(database, pSQL[i], callback, 0, &zErrMsg);

gives me an error: "near "@PLG": syntax error"

also for Tag = _T("Main Plugin1@PLG.Value1@Value");

gives me an error: "near "Plugin1": syntax error"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 22 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100