delphi一段代码,帮忙找下错。谢谢
ifmainmodel.add_stuinfoquery.RecordCount<>0thenbeginapplication.MessageBox('Äú&E...
if mainmodel.add_stuinfoquery.RecordCount<>0 then
begin
application.MessageBox('ÄúËùÒª±£´æµÄÊý¾ÝÒѾ´æÔÚ','³ö´íÀ²',mb_ok);
//mainmodel.add_stuinfoquery.Close;
// mainmodel.add_stuinfoquery.SQL.Clear;
//mainmodel.add_stuinfoquery.SQL.Add('select * from stu_info order by stu_id');
//mainmodel.add_stuinfoquery.Open;
exit;
end;
//mainmodel.add_stuinfoquery.Insert;
with mainmodel.add_stuinfoquery do
begin
close;
sql.Clear;
sql.Add('insert stu_info into id_edit=:stu_id,name_edit=:stu_name,clas_edit=:stu_clas,gender_box=:stu_gender,bir_edit=:stu_birth,add_edit=:stu_addr,phone_edit=:stu_phon,memo=:stu_memo');
//mainmodel.add_stuinfoquery.Parameters.ParamByName().Value
FieldByName('stu_id').AsString:=trim(id_edit.Text);
FieldByName('stu_name').AsString:=trim(name_edit.Text);
FieldByName('stu_clas').AsString:=trim(clas_edit.Text);
FieldByName('stu_gender').AsString:=trim(gender_box.Text);
FieldByName('stu_birth').AsDateTime:=strtodatetime(trim(bir_edit.Text));
FieldByName('stu_addr').AsString:=trim(add_edit.Text);
FieldByName('stu_phon').AsString:=trim(phone_edit.Text);
FieldByName('stu_memo').AsString:=trim(memo.Lines.Text);
mainmodel.add_stuinfoquery.ExecSQL;
end;
如上,报错。field'stu_id' not found;
谢谢,我非常的急。
mainmodel.add_stuinfoquery.Insert;
with mainmodel.add_stuinfoquery do
begin
close;
sql.Clear;
sql.Add('insert stu_info into id_edit=:stu_id,name_edit=:stu_name,clas_edit=:stu_clas,gender_box=:stu_gender,bir_edit=:stu_birth,add_edit=:stu_addr,phone_edit=:stu_phon,memo=:stu_memo');
//mainmodel.add_stuinfoquery.Parameters.ParamByName().Value
FieldByName('stu_id').AsString:=trim(id_edit.Text);
FieldByName('stu_name').AsString:=trim(name_edit.Text);
FieldByName('stu_clas').AsString:=trim(clas_edit.Text);
FieldByName('stu_gender').AsString:=trim(gender_box.Text);
FieldByName('stu_birth').AsDateTime:=strtodatetime(trim(bir_edit.Text));
FieldByName('stu_addr').AsString:=trim(add_edit.Text);
FieldByName('stu_phon').AsString:=trim(phone_edit.Text);
FieldByName('stu_memo').AsString:=trim(memo.Lines.Text);
Post;
还是那个错误 展开
begin
application.MessageBox('ÄúËùÒª±£´æµÄÊý¾ÝÒѾ´æÔÚ','³ö´íÀ²',mb_ok);
//mainmodel.add_stuinfoquery.Close;
// mainmodel.add_stuinfoquery.SQL.Clear;
//mainmodel.add_stuinfoquery.SQL.Add('select * from stu_info order by stu_id');
//mainmodel.add_stuinfoquery.Open;
exit;
end;
//mainmodel.add_stuinfoquery.Insert;
with mainmodel.add_stuinfoquery do
begin
close;
sql.Clear;
sql.Add('insert stu_info into id_edit=:stu_id,name_edit=:stu_name,clas_edit=:stu_clas,gender_box=:stu_gender,bir_edit=:stu_birth,add_edit=:stu_addr,phone_edit=:stu_phon,memo=:stu_memo');
//mainmodel.add_stuinfoquery.Parameters.ParamByName().Value
FieldByName('stu_id').AsString:=trim(id_edit.Text);
FieldByName('stu_name').AsString:=trim(name_edit.Text);
FieldByName('stu_clas').AsString:=trim(clas_edit.Text);
FieldByName('stu_gender').AsString:=trim(gender_box.Text);
FieldByName('stu_birth').AsDateTime:=strtodatetime(trim(bir_edit.Text));
FieldByName('stu_addr').AsString:=trim(add_edit.Text);
FieldByName('stu_phon').AsString:=trim(phone_edit.Text);
FieldByName('stu_memo').AsString:=trim(memo.Lines.Text);
mainmodel.add_stuinfoquery.ExecSQL;
end;
如上,报错。field'stu_id' not found;
谢谢,我非常的急。
mainmodel.add_stuinfoquery.Insert;
with mainmodel.add_stuinfoquery do
begin
close;
sql.Clear;
sql.Add('insert stu_info into id_edit=:stu_id,name_edit=:stu_name,clas_edit=:stu_clas,gender_box=:stu_gender,bir_edit=:stu_birth,add_edit=:stu_addr,phone_edit=:stu_phon,memo=:stu_memo');
//mainmodel.add_stuinfoquery.Parameters.ParamByName().Value
FieldByName('stu_id').AsString:=trim(id_edit.Text);
FieldByName('stu_name').AsString:=trim(name_edit.Text);
FieldByName('stu_clas').AsString:=trim(clas_edit.Text);
FieldByName('stu_gender').AsString:=trim(gender_box.Text);
FieldByName('stu_birth').AsDateTime:=strtodatetime(trim(bir_edit.Text));
FieldByName('stu_addr').AsString:=trim(add_edit.Text);
FieldByName('stu_phon').AsString:=trim(phone_edit.Text);
FieldByName('stu_memo').AsString:=trim(memo.Lines.Text);
Post;
还是那个错误 展开
1个回答
展开全部
你可以看下资料
xxx.insert;
xxx.fieldbyname(...).value := xxx;
...
...
post;
这是一种以字段方式插入记录
另外一种是以SQL方式
xxx.active := false;
xxx.sql.text := 'insert into xxx(字段)values(值)';
xxx.execsql;
两个不能混在一起用,你的代码...
orz...
你难道没看懂我说的意思:
mainmodel.add_stuinfoquery.Insert; //此处已经用了数据集的方法添加记录
with mainmodel.add_stuinfoquery do
begin
close;
sql.Clear;
//也就不可以在这个地方再用SQL添加记录,两者只能取其一
//至于具体的用法可以参考上面
sql.Add('insert stu_info into id_edit=:stu_id,name_edit=:stu_name,clas_edit=:stu_clas,gender_box=:stu_gender,bir_edit=:stu_birth,add_edit=:stu_addr,phone_edit=:stu_phon,memo=:stu_memo');
//当你用SQL添加记录的时候,这里应该设置参数的值,因为你好多地方用到了参数
//mainmodel.add_stuinfoquery.Parameters.ParamByName().Value
//当你用数据集的Insert方法添加记录的时候,才用fieldbyname来给字段赋值
FieldByName('stu_id').AsString:=trim(id_edit.Text);
FieldByName('stu_name').AsString:=trim(name_edit.Text);
FieldByName('stu_clas').AsString:=trim(clas_edit.Text);
FieldByName('stu_gender').AsString:=trim(gender_box.Text);
FieldByName('stu_birth').AsDateTime:=strtodatetime(trim(bir_edit.Text));
FieldByName('stu_addr').AsString:=trim(add_edit.Text);
FieldByName('stu_phon').AsString:=trim(phone_edit.Text);
FieldByName('stu_memo').AsString:=trim(memo.Lines.Text);
Post;
xxx.insert;
xxx.fieldbyname(...).value := xxx;
...
...
post;
这是一种以字段方式插入记录
另外一种是以SQL方式
xxx.active := false;
xxx.sql.text := 'insert into xxx(字段)values(值)';
xxx.execsql;
两个不能混在一起用,你的代码...
orz...
你难道没看懂我说的意思:
mainmodel.add_stuinfoquery.Insert; //此处已经用了数据集的方法添加记录
with mainmodel.add_stuinfoquery do
begin
close;
sql.Clear;
//也就不可以在这个地方再用SQL添加记录,两者只能取其一
//至于具体的用法可以参考上面
sql.Add('insert stu_info into id_edit=:stu_id,name_edit=:stu_name,clas_edit=:stu_clas,gender_box=:stu_gender,bir_edit=:stu_birth,add_edit=:stu_addr,phone_edit=:stu_phon,memo=:stu_memo');
//当你用SQL添加记录的时候,这里应该设置参数的值,因为你好多地方用到了参数
//mainmodel.add_stuinfoquery.Parameters.ParamByName().Value
//当你用数据集的Insert方法添加记录的时候,才用fieldbyname来给字段赋值
FieldByName('stu_id').AsString:=trim(id_edit.Text);
FieldByName('stu_name').AsString:=trim(name_edit.Text);
FieldByName('stu_clas').AsString:=trim(clas_edit.Text);
FieldByName('stu_gender').AsString:=trim(gender_box.Text);
FieldByName('stu_birth').AsDateTime:=strtodatetime(trim(bir_edit.Text));
FieldByName('stu_addr').AsString:=trim(add_edit.Text);
FieldByName('stu_phon').AsString:=trim(phone_edit.Text);
FieldByName('stu_memo').AsString:=trim(memo.Lines.Text);
Post;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询