异常信息(100分)

  • 主题发起人 weiqun789
  • 开始时间
W

weiqun789

Unregistered / Unconfirmed
GUEST, unregistred user!
异常信息"Table或query1 :Dateset not in edit or insert mode"怎么解决?
 
L

LSUPER

Unregistered / Unconfirmed
GUEST, unregistred user!
调用 append 或者 edit 了么 ?
 
S

superrgf

Unregistered / Unconfirmed
GUEST, unregistred user!
没有调用edit或insert就直接post导致
 
H

hds6400

Unregistered / Unconfirmed
GUEST, unregistred user!
if Table1.state in [dsEdit, dsInsert] then
Table1.Post;
 
H

hlfysj

Unregistered / Unconfirmed
GUEST, unregistred user!
同意楼上
 
X

xfeiffer

Unregistered / Unconfirmed
GUEST, unregistred user!
你用了Open吧,这样只能返回一个只读的数据集,涉及到Insert、Update、Delete的应该用ExeSQL
 
W

weiqun789

Unregistered / Unconfirmed
GUEST, unregistred user!
with table2do
begin
close;
open;
Srecord:=0;
Srecord:=recordcount+1;
insert;
Sbookno:=0;
Sbookno:=strtoint(edit1.Text);
Sstuno:=0;
Sstuno:=strtoint(edit2.Text);
BDatestr:=formatdatetime('yyyy''-''mm''-''dd',Date);
RDatestr:=copy(BDatestr,1,5)+inttostr(strtoint(copy(BDatestr,6,2))+1)+copy(BDatestr,8,3);
table2.SetFields([Srecord,Sstuno,Sbookno,BDatestr,RDatestr,False,False]);
post;
 
W

weiqun789

Unregistered / Unconfirmed
GUEST, unregistred user!
应该修改哪里呢?
 
W

weiqun789

Unregistered / Unconfirmed
GUEST, unregistred user!
我添加了“if Table1.state in [dsEdit, dsInsert] then
Table1.Post;

可是又出现异常信息”list index out of bounds(0)"这又是怎么回事
 
W

weiqun789

Unregistered / Unconfirmed
GUEST, unregistred user!
用了上面的方法还是解决不了,大家来看一下我的源代码,有借阅和预约两个功能:
procedure Tform2.BitBtn1Click(Sender: TObject);
var
BDatestr,RDatestr:string;
begin
if edit2.Text<>'' then
begin
if radiobutton1.Checked=True then
begin
with query1do
begin
close;
sql.Clear;
sql.Add('select * from student where 学号='+edit2.Text);
open;
if query1.RecordCount=0 then
begin
showmessage('学号错误!');
end
else
if query1.FieldByName('借阅许可').AsBoolean=False then
begin
showmessage('对不起,您的借书已达上限,请退出!');
form2.Close;
end
else
begin
with query1do
begin
close;
sql.Clear;
sql.Add('select * from record where 书号='+edit1.Text);
open;
end;
if query1.FieldByName('学号').AsInteger<>strtoint(edit2.Text) then
begin
with table1do
begin
close;
table1.IndexFieldNames:='书号';
table1.ReadOnly:=False;
open;
table1.FindKey([strtoint(edit1.Text)]);
edit;
table2.SetFields([nil,nil,nil,nil,nil,True,False]);
post;
end;
with table2do
begin

open;
insert;
BDatestr:=formatdatetime('yyyy''-''mm''-''dd',Date);
RDatestr:=copy(BDatestr,1,5)+inttostr(strtoint(copy(BDatestr,6,2))+1)+copy(BDatestr,8,3);
table2.SetFields([recordcount+1,strtoint(edit2.Text),strtoint(edit1.Text),BDatestr,RDatestr,False,False]);
post;
end;
showmessage('借阅成功!');
end;
end;
end;
end;
if radiobutton2.Checked=true then
begin
with query1do
begin
close;
sql.Clear;
sql.Add('select * from student where 学号='+edit2.Text);
open;
if query1.RecordCount=0 then
begin
edit2.Clear;
showmessage('学号错误!');
end
else
if query1.FieldByName('借阅许可').AsString='False' then
begin
showmessage('对不起,你的借书已达上限,请退出!');
form2.Close;
end
else
begin
with query1do
begin
close;
sql.Clear;
sql.Add('select * from record where 书号='+edit1.Text);
open;
end;
if query1.FieldByName('学号').AsInteger<>strtoint(edit2.Text) then
begin
with table1do
begin
close;
table1.IndexFieldNames:='书号';
table1.ReadOnly:=False;
open;
table1.FindKey([strtoint(edit1.Text)]);
edit;
table1.SetFields([nil,nil,nil,nil,nil,nil,True]);
post;
end;
with table2do
begin
open;
insert;
BDatestr:=formatdatetime('yyyy''-''mm''-''dd',Date);
RDatestr:=copy(BDatestr,1,5)+inttostr(strtoint(copy(BDatestr,6,2))+1)+copy(BDatestr,8,3);
table2.SetFields([recordcount+1,strtoint(edit2.Text),strtoint(edit1.Text),BDatestr,RDatestr,False,True]);
post;
end;
showmessage('预约成功!');
end
else
begin
showmessage('同一个人不能对同一本书进行借阅和预约!');
end;
end;
end;
end;

end;
with query1do
begin
close;
sql.Clear;
sql.Add('select * from record where 学号='+edit2.Text);
open;
if recordcount>=4 then
begin
with table3do
begin
table3.IndexFieldNames:='学号';
close;
readonly:=False;
open;
table3.FindKey([edit2.Text]);
edit;
setFields([nil,nil,nil,nil,nil,nil,nil,False]);
post;
end;
end;
end;
end;

end.
预约可以成功,但借阅就出现上面的异常了
 
W

weiqun789

Unregistered / Unconfirmed
GUEST, unregistred user!
with table1do
begin
close;
table1.IndexFieldNames:='书号';
table1.ReadOnly:=False;
open;
table1.FindKey([strtoint(edit1.Text)]);
edit;
table2.SetFields([nil,nil,nil,nil,nil,True,False]);
post;
end;
对不起,是我写错了代码
 
W

weiqun789

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢各位
 
B

bbscom

Unregistered / Unconfirmed
GUEST, unregistred user!
根據狀態執行:
在編輯時:table1.edit;
在插入時:table1.insert;
 
W

weiqun789

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm3.ComboBox3Change(Sender: TObject);
begin
if combobox3.ItemIndex=0 then
begin
combobox1.Items.Clear;
combobox1.Items.Add('学号');
combobox1.Items.Add('姓名');
combobox1.Items.Add('年龄');
combobox1.Items.Add('性别');
combobox1.Items.Add('班级');
combobox1.Items.Add('系别');
combobox1.Items.Add('电话号码');
combobox1.Items.Add('借阅许可');
end;
if combobox3.ItemIndex=1 then
begin
combobox1.Items.Clear;
combobox1.Items.Add('书号');
combobox1.Items.Add('书名');
combobox1.Items.Add('作者');
combobox1.Items.Add('出版社');
combobox1.Items.Add('购买时间');
combobox1.Items.Add('是否允许借阅');
combobox1.Items.Add('是否允许预约');
end;
if combobox3.ItemIndex=2 then
begin
combobox1.Items.Clear;
combobox1.Items.Add('记录号');
combobox1.Items.Add('学号');
combobox1.Items.Add('书号');
combobox1.Items.Add('借阅时间');
combobox1.Items.Add('归还时间');
combobox1.Items.Add('是否过期');
combobox1.Items.Add('是否预约');
end;
if combobox3.ItemIndex=3 then
begin
combobox1.Items.Clear;
combobox1.Items.Add('用户名');
combobox1.Items.Add('密码');
combobox1.Items.Add('权限');
end;


end;

procedure TForm3.BitBtn1Click(Sender: TObject);
begin
combobox3.Text:='';
combobox1.Text:='';
combobox2.Text:='';
edit1.Text:='';
end;

procedure TForm3.BitBtn2Click(Sender: TObject);
begin
with query1do
begin
close;
sql.Clear;
sql.Add('select * from student where '+combobox1.text+''+combobox2.text+''+edit1.text);
open;
end;

这是我做的综合查询,比如student表中是数字类型的字段可以查询得到,但是如果是其它类型的就会出现异常说”参数“小忠”没有默认值“ 我在edit1中输入“小忠”
combobox1中的内容是每个表的字段,combobox2是判断条件,比如(=,<,>....),edit1中输入对应字段的值
这些问题如何解决
 
W

weiqun789

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