Lazarus DBLookupCombobox不能将null转换为int64来提交数据。

问题描述 投票:-1回答:1

我一直在使用Lazarus 2.x和Firebird 3(通过flamerobin),我尝试通过TSQLConnection, TSQLQuery, TDataSource在数据模块中提交记录。

我成功地运行了下面的脚本,以配置最初的DBLookupCombobox,在那里记录显示没有任何问题。

procedure TForm3.FormCreate(Sender: TObject);
  begin
  appeals.SQLQuery4.Close;
  appeals.SQLQuery4.SQL.Text:='select id,fullname from promoter';

  appeals.SQLQuery4.Open;

  appeals.DataSource2.DataSet:=appeals.SQLQuery4;
  DBLookupComboBox1.ListSource:=appeals.DataSource2;
  DBLookupComboBox1.ScrollListDataset:=True;
  DBLookupComboBox1.Style:=csDropDownList;
  DBLookupComboBox1.KeyField:='id';
  DBLookupComboBox1.DataField:='id';
  DBLookupComboBox1.ListField:='fullname';    

  end;   

之后,我使用下面的片段来提交记录。

procedure TForm3.Button1Click(Sender: TObject);
begin

  appeals.SQLTransaction1.Active:=false;

  appeals.SQLQuery1.SQL.Text:='UPDATE appeals set name=:name,date_entry=:entry,date_suspended=:suspended,'+
  'date_court=:court,date_judgement=:judgement,promoter_id=:code where id='+IntToStr(row_num);

  appeals.SQLQuery1.Params.ParamByName('name').AsString:=Trim(Edit1.Text);
  appeals.SQLQuery1.Params.ParamByName('entry').AsDate:=DateTimePicker1.Date;
  appeals.SQLQuery1.Params.ParamByName('suspended').AsDate:=IncDay(DateTimePicker1.Date,10);
  appeals.SQLQuery1.Params.ParamByName('court').AsDate:=DateTimePicker2.Date;
  appeals.SQLQuery1.Params.ParamByName('judgement').AsDate:=IncDay(DateTimePicker2.Date,20);
  appeals.SQLQuery1.Params.ParamByName('code').AsInteger:=DBLookupComboBox1.KeyValue;

  appeals.SQLTransaction1.StartTransaction;
  appeals.SQLQuery1.ExecSQL;
  appeals.SQLTransaction1.Commit;
  Application.MessageBox('Record submission with success !', 'Information', MB_ICONINFORMATION);                               

 end;

我也附上了下面的脚本,在表单创建事件中,没有任何运气。维基文章.

If (DBLookupComboBox1.KeyValue = Null) And (appeals.SQLQuery4.RecordCount > 0) Then
    DBLookupComboBox1.KeyValue := appeals.SQLQuery4.FieldByName('id').AsVariant;

任何想法将帮助我很多关于DBLookupComboBox1.KeyValue出现以下错误!我想通过DBLookupComboBox1.KeyValue更新一个表的字段,从另一个表,两个datetimepickers和编辑控件加载数据。

enter image description here

我想通过DBLookupComombobox(外键)更新一个表的字段,该表从另一个表、两个datetimepickers和编辑控件中加载数据。

enter image description here

尊敬的各位

lazarus
1个回答
0
投票

我刚刚发现,之前 appeals.SQLTransaction1.Active:=false,我必须存储 DBLookupComboBox1.KeyValue 到一个本地变量中,因为之后数据库连接丢失,因此DBLookupComboBox1.KeyValue没有任何值,而是NULL。

因此,我必须在我的SQL查询中使用该本地变量来更新相应的记录。

我下次应该更加小心

© www.soinside.com 2019 - 2024. All rights reserved.