delphi 标准表达式中数据类型不匹配(ACCESS数据库)(50分)

笨笨的小孩

Unregistered / Unconfirmed
GUEST, unregistred user!
部分代码如下:
procedure DBOperation.ClearDB(AQuery1: TADOQuery;
AQuery2: TADOQuery;
Aselected: String);
var
sqlStr: String;
begin
sqlStr := 'Delete from EachYear where (YProjectID = '''+ Aselected +''')';
AddToDB2(AQuery2, sqlStr);
SqlStr := 'Delete from ProjectLoan where (projectID = '''+ Aselected + ''')';
AddToDB2(AQuery1, sqlStr);
sqlStr := 'select * from ProjectLoan order by ProjectID';
AddToDB1(AQuery1, sqlStr);
end;
procedure DBOperation.AddToDB1(AQuery: TADOQuery;AsqlStr: string);
begin
with AQuerydo
begin
close;

sql.Clear;
sql.Add(AsqlStr);
open;
end;
end;
procedure DBOperation.AddToDB2(AQuery: TADOQuery;AsqlStr: string);
begin
with AQuerydo
begin
close;
sql.Clear;
sql.Add(AsqlStr);
ExecSql;
end;
end;
为什么执行后会报标准表达式中数据类型不匹配呢? 我不知道什么原因,请各位能指教.
 
P

panpeng27934405

Unregistered / Unconfirmed
GUEST, unregistred user!
projectID 或者 YProjectID
是字符串类型 还是整型??
仔细分析分析.
我以为是这两处可能有问题
 
L

lx8598

Unregistered / Unconfirmed
GUEST, unregistred user!
YProjectID = '''+ Aselected +'''
是他们数据类型不配, 配上不就完了
 

笨笨的小孩

Unregistered / Unconfirmed
GUEST, unregistred user!
projectID,YprojectID都是整型的..
 
T

th_lmy

Unregistered / Unconfirmed
GUEST, unregistred user!
Aselected 是字符串,YProjectID 又是整型,则:
sqlStr := 'Delete from EachYear where ( YProjectID = '+ Aselected +' )';
 

程序人

Unregistered / Unconfirmed
GUEST, unregistred user!
sqlStr := 'Delete from EachYear where (YProjectID = '+ Aselected+')';
这样写是没有问题的;下句相同去掉多余的引号就ok了
 

笨笨的小孩

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
Top Bottom