将CString的值添加到SQLite数据库 [英] Add value of a CString to the SQLite database

查看:272
本文介绍了将CString的值添加到SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的CString的值添加到已经创建的datbase中.

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);



当我执行命令时,我收到一条错误消息数据库中没有名称为textvalue的列".

如何在运行时将值"DarkKnight"插入SQLite数据库.



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.

推荐答案

这里是我在C ++ cgi模块中使用的代码. >
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;
db.exe(queryStr);



大概,您似乎已经在PHP中使用过mySql,这是因为您希望用变量的内容代替变量名.


我在MFC中重击的内容:



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.


something I whacked together in MFC:

void CmfcSqliteDlg::OnBnClickedButton1()
{
	USES_CONVERSION;
	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);
}


这篇关于将CString的值添加到SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆