Path := ExtractFilePath(Application.ExeName);
DBPath := Path + 'DB';
TableName := 'QDK.DB'; QDH := '010101001'; Query1.DatabaseName := DBPath;
Command := 'Select * from ' + TableName + ' where QDH = ' + '''' + QDH + '''';
对“'''' + QDH + ''''”的理解:
形成“''010101001''”
整个句子形成“Select * from QDK.DB where QDH = ''010101001 ''”
应该是“Select * from QDK.DB where QDH = '010101001'”
而写成
Command := 'Select * from ' + TableName + ' where QDH = ' + ''' + QDH + ''';
不行
应该形成“Select * from QDK.DB where QDH = '' + QDH + ''”
而实际形成的是“Select * from QDK.DB where QDH = ' + QDH + '”
DBPath := Path + 'DB';
TableName := 'QDK.DB'; QDH := '010101001'; Query1.DatabaseName := DBPath;
Command := 'Select * from ' + TableName + ' where QDH = ' + '''' + QDH + '''';
对“'''' + QDH + ''''”的理解:
形成“''010101001''”
整个句子形成“Select * from QDK.DB where QDH = ''010101001 ''”
应该是“Select * from QDK.DB where QDH = '010101001'”
而写成
Command := 'Select * from ' + TableName + ' where QDH = ' + ''' + QDH + ''';
不行
应该形成“Select * from QDK.DB where QDH = '' + QDH + ''”
而实际形成的是“Select * from QDK.DB where QDH = ' + QDH + '”
'a''a'表示 a'a
例如:
'Select A from table where B='+QuotedStr(Str1)+' and a>100';