我的数据库里面除了系统自动添加的主键外有4个字段,分别为BZM,ZH,YFLH,ZWM,可是我用查询语句
sql.add('update w set BZM=:BZM,ZH=:ZH,YFLH=:YFLH,ZWM=:ZWM '
+'where BZM='''+edit2.text+'''');
时候只能更新后面3个字段,BZM无法更新,是为什么啊?代码如下:
if radiobutton6.Checked then
begin
try
with DataModule2.ADOQuery1 do
begin
sql.Clear ;
sql.add('update w set BZM=:BZM,ZH=:ZH,YFLH=:YFLH,ZWM=:ZWM '
+'where BZM='''+edit2.text+'''');
parameters.ParamByName('BZM').Value :=edit2.Text ;
parameters.ParamByName('ZH').Value :=edit3.Text ;
parameters.ParamByName('YFLH').Value :=edit4.Text ;
parameters.ParamByName('ZWM').Value :=edit5.Text ;
execsql;
sql.clear;
sql.add('select * from w ');
open;
listview1.Items.Clear ;
while not eof do
begin
with listview1.Items.Add do
begin
caption:=fieldbyname('BZM').asstring;
subitems.Add(fieldbyname('ZH').asstring);
subitems.Add(fieldbyname('YFLH').asstring);
subitems.Add(fieldbyname('ZWM').asstring);
end;
next;
end;
close;
sql.add('update w set BZM=:BZM,ZH=:ZH,YFLH=:YFLH,ZWM=:ZWM '
+'where BZM='''+edit2.text+'''');
时候只能更新后面3个字段,BZM无法更新,是为什么啊?代码如下:
if radiobutton6.Checked then
begin
try
with DataModule2.ADOQuery1 do
begin
sql.Clear ;
sql.add('update w set BZM=:BZM,ZH=:ZH,YFLH=:YFLH,ZWM=:ZWM '
+'where BZM='''+edit2.text+'''');
parameters.ParamByName('BZM').Value :=edit2.Text ;
parameters.ParamByName('ZH').Value :=edit3.Text ;
parameters.ParamByName('YFLH').Value :=edit4.Text ;
parameters.ParamByName('ZWM').Value :=edit5.Text ;
execsql;
sql.clear;
sql.add('select * from w ');
open;
listview1.Items.Clear ;
while not eof do
begin
with listview1.Items.Add do
begin
caption:=fieldbyname('BZM').asstring;
subitems.Add(fieldbyname('ZH').asstring);
subitems.Add(fieldbyname('YFLH').asstring);
subitems.Add(fieldbyname('ZWM').asstring);
end;
next;
end;
close;
二者不同就行了
1.
sql.add('update w set BZM=:BZM,ZH=:ZH,YFLH=:YFLH,ZWM=:ZWM '
+'where BZM='''+edit2.text+'''');
更新BZM=edit2.text的记录
2.
parameters.ParamByName('BZM').Value :=edit2.Text ;
将bzm更新为edit2.text
所以一样啊
+'where BZM='''+edit2.text+'''');//问题所在
parameters.ParamByName('BZM').Value :=edit2.Text ; //问题所在
这上面是要更新的
+'where BZM='''+edit2.text+'''');这是条件
老大别晕啊