本来此问题已经结贴了,却遇到新问题了.原问题:Form中有三个空间:DataTimePicker    Button    DbGrid希望得到的效果是同过Button的Click事件在DataTimePicker的内容,批量写入Access表中的某一字段列.
比如:在DataTimePicker中设定一个时间(2006-8-4),然后机型Button的Click事件后,得下表:编号  ……     时间
 1    ……   2006-8-4
 2    ……   2006-8-4
 3    ……   2006-8-4答案:var Num,i,j :integer;    Num :=1;
    i :=0;
    j :=100;
    while i<j do
    begin
      adoquery1.Insert;
      adoquery1.FieldByName('Num_no').AsString:=Inttostr(Num);
      adoquery1.FieldByName('DT').AsString:=datetostr(DataTimePicker1.date);
      adoquery1.Post;
      Inc(Num);
      Inc(i) ;
    end;
但是如果我的表除了编号和时间外还有其他字段,比如货物名称那么应用以上语句就会出现:编号  ……    货物名称     时间
 1    ……     ××
 2    ……     ××
 3    ……     ××
 4    ……                2006-8-4
 5    ……                2006-8-4
 6    ……                2006-8-4
 7    ……                2006-8-4
103   ……                2006-8-4也就是从货物名称为空时才开始填入时间。
原来的表是:货物名称      时间
  ××
  ××
  ××  那么请问如何写才能直接得到下表呢?货物名称     时间
   ××       2006-8-4 
   ××       2006-8-4
   ××       2006-8-4

解决方案 »

  1.   

    晕~~~一样的啊`~    Num :=1;
        i :=0;
        j :=100;
        while i<j do
        begin
          adoquery1.Insert;
          adoquery1.FieldByName('编号').AsString:=Inttostr(Num);
          adoquery1.FieldByName('货物名称').AsString:='××';
          adoquery1.FieldByName('时间').AsString:=datetostr(DataTimePicker1.date);
          adoquery1.Post;
          Inc(Num);
          Inc(i) ;
        end;
      

  2.   

    不好意思,没说清楚,货物名不是同一个名,比如有货物a,货物b,货物c等。
      

  3.   

    哪你就不能用批处理了``一条条POST
      

  4.   

    哦,那么是否可以这样做呢?在表中加入一个逻辑类型的字段,当在表中此字段的a行选择true的时候,就把DataTimePicker1中的值放到a行的时间字段中?比如:
      进货与否     时间       货物名称
        是       2006-8-4       ××
        否                      ×××
        是       2006-8-4       ××1
      

  5.   

    with adoquery1 do
        begin
          first;
          while not eof do
          begin
            if not FieldByName('进货与否').asboolean then eixt;
            if not (state in [dsinsert,dsedit]) then edit;
            FieldByName('时间').asdatetime:=DataTimePicker1.date;
            Post;
            next;
          end;
       end;
      

  6.   

    把first去掉,否则永远只能更新第一行的数据。
      

  7.   

    呵呵`~~没仔细看代码 
       with adoquery1 do
        begin
          first;
          while not eof do
          begin
            if FieldByName('进货与否').asboolean then 
            begin
              if not (state in [dsinsert,dsedit]) then edit;
              FieldByName('时间').asdatetime:=DataTimePicker1.date;
              Post;
            end;
            next;
          end;
       end;