在save()中:
...
DataSet.Append;
EditDate.Text:=DateToStr(theDate);//《---赋了值了呀?
EditSectionOffice.Text:=theOffice;for intCount:=0 to Self.ComponentCount-1 do
   if (self.Components[intCount] is TEdit) then
   begin
     strField:=self.Components[intCount].Name;
     strField:='sp'+Copy(strField,5,Length(strField)-4);
     FieldValues[strField]:=(self.Components[intCount] as TEdit).Text;
     Post;
   end;{if self.Components[intCount] is TEdit }
...报错如下:spDate不允许插入空值。
怎么会这样呢?

解决方案 »

  1.   

    检查一下DateToStr(theDate)的值是否正常
      

  2.   

    你先这样处理一下,把for循环去掉,看看EditDate控件中是不是真的有了一个日期值,
    如果有日期值,那么你数据表的spDate字段真的是string类型么?还是DateTime类型?
      

  3.   

    你的Components是个什么东东?用断点追踪一下,看一下值能传递到什么地方!
      

  4.   

    顶一下吧
    Note: This code does not save the form or data module to disk after the nonvisual components are moved.  If executed at runtime, the effect will not persist.var  I: Integer;
      Temp: TComponent;
    begin
      for I := ComponentCount - 1 downto 0 do
      begin
        Temp := Components[I];
        if not (Temp is TControl) then
        begin
          RemoveComponent(Temp);
          DataModule2.InsertComponent(Temp);
        end;
      end;end;
      

  5.   

    是datetime类型,我怕改成string会影响到其它地方。
      

  6.   

    猜想,确实如你所言spDate字段定义为非空。
    所以在这个地方DataSet.Append;你已经出错的,不信你自己设个断点试试。
    因为你用无参数的Append,也就是所有的字段都未赋值,spDate的命运当然相同,所以如果你想Append一条记录,必须用带参数的Append,必须给那些非空的字段赋一个缺省值(随便一个合法的值都可),反正你在随后的代码中要赋值的,
    要不你先把所有的值都计算完成后再用带参数的Append(...)把这条记录追加上去。
      

  7.   

    for intCount:=0 to Self.ComponentCount-1 do
       if (self.Components[intCount] is TEdit) then
       begin
         strField:=self.Components[intCount].Name;
         strField:='sp'+Copy(strField,5,Length(strField)-4);
         //加上这条看看是不是真的有值啊
         ShowMessage((self.Components[intCount] as TEdit).Text);
         //加上这条看看是不是真的有值啊
         FieldValues[strField]:=(self.Components[intCount] as TEdit).Text;
         Post;
       end;{if self.Components[intCount] is TEdit }还有FieldValues[spDate]是什么类型的字段啊?你往里面赋String类型?