我在一个edit1框内的onchange事件中写了一个update语句,想实现自动保存功能,自己检测到只要当输入字符 ' 时,便出错,请问这是什么原因,怎样解决?update如下,看有错没,谢谢... with DM_1 do
begin
AdoQ_update.Close;
AdoQ_update.SQL.Clear;
AdoQ_update.SQL.Add('update diary');
AdoQ_update.SQL.Add('set subject = '''+re_sub.text+'''');
AdoQ_update.SQL.Add('where name = '''+gs_user+'''' + 'and year = ''' + s_year + '''');
AdoQ_update.SQL.Add('and number = '+inttostr(i_num)+'');
AdoQ_update.ExecSQL;
end;
begin
AdoQ_update.Close;
AdoQ_update.SQL.Clear;
AdoQ_update.SQL.Add('update diary');
AdoQ_update.SQL.Add('set subject = '''+re_sub.text+'''');
AdoQ_update.SQL.Add('where name = '''+gs_user+'''' + 'and year = ''' + s_year + '''');
AdoQ_update.SQL.Add('and number = '+inttostr(i_num)+'');
AdoQ_update.ExecSQL;
end;
key := 0;
导致sql语句出错
楼上的写法可以屏蔽输入关键字符
begin
AdoQ_update.Close;
AdoQ_update.SQL.Clear;
AdoQ_update.SQL.Add('update diary');
AdoQ_update.SQL.Add('set subject = '''+re_sub.text+'''');
AdoQ_update.SQL.Add('where name = '''+gs_user+'''' + 'and year = ''' + s_year + '''');
AdoQ_update.SQL.Add('and number = '+inttostr(i_num)+'');
AdoQ_update.ExecSQL;
end;
' 多了容易看错,用 with DM_1 do
begin
AdoQ_update.Close;
AdoQ_update.SQL.Clear;
AdoQ_update.SQL.Add('update [diary]');
AdoQ_update.SQL.Add('set [subject] = '+#39+re_sub.text+#39 );
AdoQ_update.SQL.Add('where [name] = '+#39+gs_user+#39+ ' and [year] =' #39+s_year + #39);
AdoQ_update.SQL.Add('and [number] = '+inttostr(i_num));
AdoQ_update.ExecSQL;
end;
begin
AdoQ_update.Close;
AdoQ_update.SQL.Clear;
AdoQ_update.SQL.Add('update diary');
AdoQ_update.SQL.Add('set subject = '''+re_sub.text+'''');
AdoQ_update.SQL.Add('where name = '''+gs_user+'''' + 'and year = ''' + s_year + '''');
AdoQ_update.SQL.Add('and number = '+inttostr(i_num)+'');
AdoQ_update.ExecSQL;
end;
语法有问题 with DM_1 do
begin
AdoQ_update.Close;
AdoQ_update.SQL.Clear;
AdoQ_update.SQL.Add('update diary ');//这里少一空格
AdoQ_update.SQL.Add('set subject = '''+re_sub.text+''' ');//又少一空格
AdoQ_update.SQL.Add('where name = '''+gs_user+'''' + 'and year = ''' + s_year + ''' '); 又少一空格
AdoQ_update.SQL.Add('and number = '+inttostr(i_num)+'');
AdoQ_update.ExecSQL;
建议出错后用AdoQ_update.sql.savetofile('C:/123.txt');打开看看123.txt,如果没有问题,就把他单独执行,如果有问题,就是关键字的问题了
'where name = '+''''+gs_user+'''' + 'and year = '+'''' + s_year + ''''+
'and number = '+''''inttostr(i_num)+'''');你试试这样.看行不行.