K
kofoun
Unregistered / Unconfirmed
GUEST, unregistred user!
我的平台为delphi7+sqlserver2000,开发一个简单的c/s数据库系统(ado的),无非就是新增,修改,保存,取消一些事件而已,但一按新增,然后按保存按钮后,就报:
Dataset not in edit or insert mode
请问怎么解决
---------------------------------------------------------
我的新增事件如下:
procedure Tform_main.addBtnClick(Sender: TObject);
begin
dm.adoq1.close;
dm.ADOQ1.SQL.Clear;
dm.adoq1.SQL.Text:=('select * from bdailytable where fdate='''+datetostr(DateTime1.date)+''' and fline = '''+linecombox.text+''' and fproductname = '''+productnamecombox.text+''' order by fdate desc');
dm.adoq1.open;
dm.ADOQ1.append;
end;
--------------------------------------------------------------
保存事件如下就是将各个文本框的值保存到数据中)
procedure Tform_main.savelBtnClick(Sender: TObject);
begin
try
dm.ADOQ1.FieldByName('fdate').AsDateTime:=strtodate(Formatdatetime('yyyy-mm-dd', DateTime1.Date));
dm.ADOQ1.FieldByName('fline').AsString:=linecombox.Text;
dm.ADOQ1.FieldByName('fmaster').AsString:=mastercombox.Text;
dm.ADOQ1.FieldByName('fproductname').AsString:=productnamecombox.Text;
dm.ADOQ1.FieldByName('fgoodscount').AsString:=goodscount.Text;
dm.ADOQ1.FieldByName('fprojectname').AsString:=projectnamecombox.Text;
dm.ADOQ1.FieldByName('fcheckcount').Asstring:=trim(checkcount.Text);
dm.ADOQ1.FieldByName('fcheckokcount').Asstring:=trim(checkokcount.Text);
dm.ADOQ1.FieldByName('fcheckproject').AsString:=checkprojectcombox.Text;
dm.ADOQ1.FieldByName('fcheckng').Asstring:=trim(checkng.Text);
dm.ADOQ1.FieldByName('foutcount').Asstring:=trim(outcount.Text);
dm.ADOQ1.FieldByName('fperson').AsString:=trim(person.text);
if checkbox1.Checked then
begin
dm.ADOQ1.FieldByName('fdailytime').Asstring:=floattostr(im1);
dm.ADOQ1.FieldByName('fovertime').AsString:=floattostr(im2);
dm.ADOQ1.FieldByName('ftotaltime').AsString:=floattostr(im3);
end
else
begin
dm.ADOQ1.FieldByName('fdailytime').Asstring:=floattostr(ia1); //正常时间
dm.ADOQ1.FieldByName('fovertime').Asstring:=floattostr(ia2); //加班时间
dm.ADOQ1.FieldByName('ftotaltime').AsString:=floattostr(ia3); //加班合计
end;
dm.ADOQ1.Post;
except
showmessage('保存失败!') ;
end;
end;
修改事件如下当我按修改按钮后,将dbgrid某行记录,赋给各个文本框)
------------------------------------------------
procedure Tform_main.modifyBtnClick(Sender: TObject);
begin
if dm.ADOQ1.RecordCount>0 then
begin
try
with dm.ADOQ1 do
begin
DateTime1.date := StrToDate(FieldValues['fdate']);
linecombox.Text := FieldValues['fline'];
mastercombox.Text := FieldValues['fmaster'];
productnamecombox.Text := FieldValues['fproductname'];
if (FieldValues['fgoodscount'])=null then
goodscount.text:=''
else
goodscount.Text := inttostr(FieldValues['fgoodscount']);
projectnamecombox.Text := FieldValues['fprojectname'];
if (FieldValues['fcheckcount'])=null then
checkcount.Text:=''
else
checkcount.Text := inttostr(FieldValues['fcheckcount']);
if (FieldValues['fcheckokcount'])=null then
checkokcount.Text:=''
else
checkokcount.Text := inttostr(FieldValues['fcheckokcount']);
if (FieldValues['fcheckng'])=null then
checkng.Text:=''
else
checkng.Text := inttostr(FieldValues['fcheckng']);
if (FieldValues['foutcount'])=null then
outcount.Text:=''
else
outcount.Text := inttostr(FieldValues['foutcount']);
if (FieldValues['fperson'])=null then
person.Text:=''
else
person.Text := inttostr(FieldValues['fperson']);
if(FieldValues['fdailytime'])=null then
dailytime1.Text:=''
else
dailytime1.Text:=floattostr(FieldValues['fdailytime']);
if(FieldValues['fovertime'])=null then
overtime1.Text:=''
else
overtime1.Text:=floattostr(FieldValues['fovertime']);
checkprojectcombox.Text := FieldValues['fcheckproject'];
edit;
end;
except
showmessage('编辑失败!');
end;
end
else
begin
showmessage('没有选中记录!');
end;
end;
---------------------------------------------------
取消事件如下:
procedure Tform_main.cancelBtnClick(Sender: TObject);
begin
dm.ADOQ1.Cancel;
end;
Dataset not in edit or insert mode
请问怎么解决
---------------------------------------------------------
我的新增事件如下:
procedure Tform_main.addBtnClick(Sender: TObject);
begin
dm.adoq1.close;
dm.ADOQ1.SQL.Clear;
dm.adoq1.SQL.Text:=('select * from bdailytable where fdate='''+datetostr(DateTime1.date)+''' and fline = '''+linecombox.text+''' and fproductname = '''+productnamecombox.text+''' order by fdate desc');
dm.adoq1.open;
dm.ADOQ1.append;
end;
--------------------------------------------------------------
保存事件如下就是将各个文本框的值保存到数据中)
procedure Tform_main.savelBtnClick(Sender: TObject);
begin
try
dm.ADOQ1.FieldByName('fdate').AsDateTime:=strtodate(Formatdatetime('yyyy-mm-dd', DateTime1.Date));
dm.ADOQ1.FieldByName('fline').AsString:=linecombox.Text;
dm.ADOQ1.FieldByName('fmaster').AsString:=mastercombox.Text;
dm.ADOQ1.FieldByName('fproductname').AsString:=productnamecombox.Text;
dm.ADOQ1.FieldByName('fgoodscount').AsString:=goodscount.Text;
dm.ADOQ1.FieldByName('fprojectname').AsString:=projectnamecombox.Text;
dm.ADOQ1.FieldByName('fcheckcount').Asstring:=trim(checkcount.Text);
dm.ADOQ1.FieldByName('fcheckokcount').Asstring:=trim(checkokcount.Text);
dm.ADOQ1.FieldByName('fcheckproject').AsString:=checkprojectcombox.Text;
dm.ADOQ1.FieldByName('fcheckng').Asstring:=trim(checkng.Text);
dm.ADOQ1.FieldByName('foutcount').Asstring:=trim(outcount.Text);
dm.ADOQ1.FieldByName('fperson').AsString:=trim(person.text);
if checkbox1.Checked then
begin
dm.ADOQ1.FieldByName('fdailytime').Asstring:=floattostr(im1);
dm.ADOQ1.FieldByName('fovertime').AsString:=floattostr(im2);
dm.ADOQ1.FieldByName('ftotaltime').AsString:=floattostr(im3);
end
else
begin
dm.ADOQ1.FieldByName('fdailytime').Asstring:=floattostr(ia1); //正常时间
dm.ADOQ1.FieldByName('fovertime').Asstring:=floattostr(ia2); //加班时间
dm.ADOQ1.FieldByName('ftotaltime').AsString:=floattostr(ia3); //加班合计
end;
dm.ADOQ1.Post;
except
showmessage('保存失败!') ;
end;
end;
修改事件如下当我按修改按钮后,将dbgrid某行记录,赋给各个文本框)
------------------------------------------------
procedure Tform_main.modifyBtnClick(Sender: TObject);
begin
if dm.ADOQ1.RecordCount>0 then
begin
try
with dm.ADOQ1 do
begin
DateTime1.date := StrToDate(FieldValues['fdate']);
linecombox.Text := FieldValues['fline'];
mastercombox.Text := FieldValues['fmaster'];
productnamecombox.Text := FieldValues['fproductname'];
if (FieldValues['fgoodscount'])=null then
goodscount.text:=''
else
goodscount.Text := inttostr(FieldValues['fgoodscount']);
projectnamecombox.Text := FieldValues['fprojectname'];
if (FieldValues['fcheckcount'])=null then
checkcount.Text:=''
else
checkcount.Text := inttostr(FieldValues['fcheckcount']);
if (FieldValues['fcheckokcount'])=null then
checkokcount.Text:=''
else
checkokcount.Text := inttostr(FieldValues['fcheckokcount']);
if (FieldValues['fcheckng'])=null then
checkng.Text:=''
else
checkng.Text := inttostr(FieldValues['fcheckng']);
if (FieldValues['foutcount'])=null then
outcount.Text:=''
else
outcount.Text := inttostr(FieldValues['foutcount']);
if (FieldValues['fperson'])=null then
person.Text:=''
else
person.Text := inttostr(FieldValues['fperson']);
if(FieldValues['fdailytime'])=null then
dailytime1.Text:=''
else
dailytime1.Text:=floattostr(FieldValues['fdailytime']);
if(FieldValues['fovertime'])=null then
overtime1.Text:=''
else
overtime1.Text:=floattostr(FieldValues['fovertime']);
checkprojectcombox.Text := FieldValues['fcheckproject'];
edit;
end;
except
showmessage('编辑失败!');
end;
end
else
begin
showmessage('没有选中记录!');
end;
end;
---------------------------------------------------
取消事件如下:
procedure Tform_main.cancelBtnClick(Sender: TObject);
begin
dm.ADOQ1.Cancel;
end;