如何把listbox1中的记录逐条保存到数据库中去,并且限制条数例如5条,我给60分快回答
我马上结贴。

解决方案 »

  1.   

    for I := 0 to ListBox1.Items.Count - 1 do
    begin
      if I = 5 then break;
      Query1.Append;
      Query1.FieldByName('abcd').AsString := ListBox1.Items[I];
      Query1.Post;
    end;
      

  2.   

    query还没有大开那?怎么对那,并且我着个表中有个自增长的字段,但是不能空。怎么调试都过不去
      

  3.   

    for i := 0 to 4 do
    begin
      with query1 do
      begin
        open;
        insert;
        FieldByName('abcd').AsString := ListBox1.Items[i];
        close;
        post;
      end;
    end;
      

  4.   

    或者定义一个常量。上面的有错。const Max: integer = 5;for i := 0 to Max - 1 do
    begin
      with query1 do
      begin
        open;
        insert;
        FieldByName('abcd').AsString := ListBox1.Items[i];
        post;
        close;
      end;
    end;
      

  5.   

    用TABLE吧 QUERY好象不行 方法一样 循环提取ITEMS各条字符串
      

  6.   

    同意上 risingsoft(一苇渡江) 但需要 加入 ListBox1.Items[i]<> ''if Table1.Active then
    for i := 0 to Max - 1 do
    begin
      if ListBox1.Items[i] <>'' then
      Table1.Append;
      Table1.FieldByName('abcd').AsString := ListBox1.Items[I];
      Table1.Post;
    end;
      

  7.   

    有误
    var i , j : Integer;
    j := 0;
    for i := 0 to ListBox1.Items.Count - 1 do
    begin
      if ListBox1.Items[i] <>'' then
      while j < 5 do
      begin
      j := j+1;
      Table1.Append;
      Table1.FieldByName('abcd').AsString := ListBox1.Items[I];
      Table1.Post; end;
    end;