我用一个DateTimePicker控件往一个数据库字段中输值,但我想写一个空值到这个数据库字段中时,如何去做?

解决方案 »

  1.   

    beforepost事件中处理如:if condi then
      DataSet.FieldByName('FieldName').AsVariant := NULL;
      

  2.   

    強烈建議你用wwDBDateTimePicker,
    如果你想輸入null值,你可以不輸入值到DateTimePicker里啊!
      

  3.   

    同意楼上,我也是用的WWDBDATETIMEPICKER很好用的 。
      

  4.   

    用一个Edit1和一个DateTimePicker。将DateTimePicker的大小变小(只剩哪个按扭大小)放在Edit右边。用Edit控件往一个数据库字段中输值。DateTimePicker来控制Edit的值。
    procedure TForm1.DateTimePicker1CloseUp(Sender: TObject);
    begin
      Edit1.Text:=DateToStr(DataTimePicker1.Date);
    end;当Edit1为空就是空值
      

  5.   

    设置TDateTiemPicker控件的为ShowCheckBoxTrue.需要插入日期时,将CheckBox选中,并选择你具体的日期;不需要插入日期时即插入空时,将CheckBox去掉选中。然后在写Insert语句时判断:
    var
      dateStr : String;
      InsertStr: sTring;
    if DateTiemPicker1.Checked then
    begin
      DateStr := FormatDateTime('yyyy-mm-dd', DateTimePicker1.DateTime);
      InsertStr :='inset into tablename (RQ_Field) values (to_date('+QuotedStr(datestr)+',''yyyy-mm-dd''))';
    end
    else 
      InsertStr := 'inset into tablename (RQ_Field) values ( null);最后执行此Sql 即可。