用一个Edit1和一个DateTimePicker。将DateTimePicker的大小变小(只剩哪个按扭大小)放在Edit右边。用Edit控件往一个数据库字段中输值。DateTimePicker来控制Edit的值。 procedure TForm1.DateTimePicker1CloseUp(Sender: TObject); begin Edit1.Text:=DateToStr(DataTimePicker1.Date); end;当Edit1为空就是空值
设置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 即可。
DataSet.FieldByName('FieldName').AsVariant := NULL;
如果你想輸入null值,你可以不輸入值到DateTimePicker里啊!
procedure TForm1.DateTimePicker1CloseUp(Sender: TObject);
begin
Edit1.Text:=DateToStr(DataTimePicker1.Date);
end;当Edit1为空就是空值
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 即可。