如何在查询表达式中修复语法错误(缺少运算符)? [英] How can i fix syntax error(missing operator) in query expression?

查看:184
本文介绍了如何在查询表达式中修复语法错误(缺少运算符)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用MFC CDatabase类访问excel文件。

代码如下。



CString sqlStr;

sqlStr.Format(_T(INSERT INTO [Sheet1 $](Name,UnderName,Profile,Symstoms,Relationship)VALUES(\'%s \',\'%s \',\ '%s \',\'%s \',\'%s \'))

,name,underName,profile,symstoms,relationShip);



m_database.ExecuteSQL(sqlStr);



但它显示错误。

In我的头脑名称值包括'character。'他是

所以我删除了'。错误是固定的。

但我不能删除这个角色。

我该如何解决这个问题?

提前谢谢。



我尝试过:



我尝试使用MFC执行查询到excel CDatabase类。

I tried to access excel file using MFC CDatabase class.
Code is as follows.

CString sqlStr;
sqlStr.Format(_T("INSERT INTO [Sheet1$] (Name, UnderName, Profile, Symstoms, Relationship) VALUES (\'%s\', \'%s\', \'%s\', \'%s\', \'%s\')")
, name, underName, profile, symstoms, relationShip);

m_database.ExecuteSQL(sqlStr);

But it shows errors.
In my mind name value include ' character."He's"
So i removed '. Error is fixed.
But I cann't remove this character.
How can i fix this?
Thanks in advance.

What I have tried:

I tried to execute query to excel using MFC CDatabase class.

推荐答案

(名称,UnderName,Profile,Symstoms,Relationship)VALUES(\'%s \',\'%s \' ,\'%s \',\'%s \',\'%s \'))

,name,underName,profile,symstoms,relationShip);



m_database.ExecuteSQL(sqlStr);



但它显示错误。

在我看来,名字值包括'字符。'他是

所以我删除了。。错误是固定的。

但是我不能删除这个字符。

我该如何解决这个问题?

提前致谢。



我尝试了什么:



我尝试使用MFC CDatabase类执行查询到Excel。
(Name, UnderName, Profile, Symstoms, Relationship) VALUES (\'%s\', \'%s\', \'%s\', \'%s\', \'%s\')")
, name, underName, profile, symstoms, relationShip);

m_database.ExecuteSQL(sqlStr);

But it shows errors.
In my mind name value include ' character."He's"
So i removed '. Error is fixed.
But I cann't remove this character.
How can i fix this?
Thanks in advance.

What I have tried:

I tried to execute query to excel using MFC CDatabase class.


问题是您正在使用字符串连接来构建SQL查询。你真的不能这样做是因为你刚刚找到的原因。


谷歌的SQL参数化查询如何解决它。
The problem is that you're using string concatenation to build the SQL query. You really can't do that for the very reason you just found.

Google for "SQL Parameterized queries" for how to fix it.


这篇关于如何在查询表达式中修复语法错误(缺少运算符)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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