用VS2010使用C++写MySQL程序,使用mysql_real_query总弹错误提示!

soundbird 2012-11-30 10:59:24
我之前用VC6.0编写使用MySQL的程序,没有出问题,一样的代码,复制到VS2010就出错,请有经验的人指点。

CString strExecuteSQL, strTableName, strDataTime;
//strTableName, strDataTime, pCollectData就不多说了
strExecuteSQL.Format(_T("insert into %s values('%s', '%.1f', '%.1f', '%.1f', '%.1f', '%.1f')"),
strTableName, strDataTime, pCollectData->dAValue, pCollectData->dBValue, pCollectData->dCValue, pCollectData->dDValue, pCollectData->dEValue);

if ( mysql_real_query(&m_mysql, (char*)(LPCTSTR)strExecuteSQL, (UINT)strExecuteSQL.GetLength()) != 0)
{
const char* pCh = mysql_error(&m_mysql);
CString strTemp;
strTemp = pCh;
AfxMessageBox(strTemp);
return;
}

执行mysql_real_query这句话时候总出错,弹错误提示“You have an error in your SQL Syntax; Check the manual that corresponds to your MySQL Server version for the right syntax to use near 'i' at line 1”。可是我检查SQL语法没有错,无奈……
...全文
312 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
演绎华丽奇迹 2015-01-15
  • 打赏
  • 举报
回复
mysql_free_result(&m_mysql);
I_ask_who 2012-11-30
  • 打赏
  • 举报
回复
VC6默认是MBCS,VC2010默认是UNICODE (char*)(LPCTSTR)strExecuteSQL 就是将wchar_t*强制转换成char*,所以语句已经变成乱码 用CStringA代替CString...
Mr_Nice 2012-11-30
  • 打赏
  • 举报
回复
lz 转到相应的板块吧...
soundbird 2012-11-30
  • 打赏
  • 举报
回复
引用 2 楼 mcmcmc 的回复:
VC6默认是MBCS,VC2010默认是UNICODE (char*)(LPCTSTR)strExecuteSQL 就是将wchar_t*强制转换成char*,所以语句已经变成乱码 用CStringA代替CString...
明白了,谢谢

4,018

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧