首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

插入一个字符串变量到数据库报MISSING OPERATOR OR semicolon异常,请朋友进来指教上具体写法

2012-10-18 
插入一个字符串变量到数据库报MISSING OPERATOR OR semicolon错误,请朋友进来指教下具体写法最好再给我解

插入一个字符串变量到数据库报MISSING OPERATOR OR semicolon错误,请朋友进来指教下具体写法
最好再给我解释下DEIPHI的单引号在SQL字符串中怎样用的谢谢

Delphi(Pascal) code
sql1:='INSERT INTO tbl_SMSendTask';sql2:=' (CreatorID,SmSendedNum,OperationType,SendType,OrgAddr,DestAddr,SM_Content,SendTime,NeedStateReport,ServiceID,FeeType,FeeCode,SMType,MessageID,DestAddrType,SubTime,TaskStatus,SendLevel,SendState,TryTimes)';sql3:=' VALUES('TEST', 0, 'was',1, 'null', '15818548017','''+rstr+''', getdate(),0, 'MGD0019901', '01', '000000',0,'',0, getdate(),0,0,0,3)';sql:=sql1+sql2+sql3;//ADOQuery2.SQL.Text:='insert into message(message) values('''+rstr+''')';ADOQuery2.SQL.Text:=sql;AdoQuery2.ExecSQL;

这个是华为发短信用的。其中sql3里的rstr是要替代的字符串数据。原SQL语句按照下面的写就能发出短信,这里将发出的内容替换成rstr字符串。请问下如何写才正确。

String sql1="INSERT INTO tbl_SMSendTask";
String sql2=" (CreatorID,SmSendedNum,OperationType,SendType,OrgAddr,DestAddr,SM_Content,SendTime,NeedStateReport,ServiceID,FeeType,FeeCode,SMType,MessageID,DestAddrType,SubTime,TaskStatus,SendLevel,SendState,TryTimes)";
String sql3=" VALUES('TEST', 0, 'was',1, 'null', '15818548017', '短信测试TEST', getdate(),0, 'MGD0019901', '01', '000000',0,'',0, getdate(),0,0,0,3)";
String sql =sql1+sql2+sql3;

[解决办法]
Delphi(Pascal) code
sql3:=' VALUES(''TEST'', 0, ''was'',1, ''null'', ''15818548017'','''+rstr+''', getdate(),0, ''MGD0019901'', ''01'', ''000000'',0,'''',0, getdate(),0,0,0,3)';
[解决办法]
sql3:=' values('''+'test'''+',0,'''+'was'''+',1,'+'null'+','''+'158988349'''+','''+rstr+''''+',getdate(),0,'''+''MGD0019901'''+','''+'01'''+','''+'000000'''+',0,getdate(),0,0,0,3)';

热点排行