首先我已经创建了一个表,然后用代码创建字段,名字是不固定的,然后添加数据,第一个添加的字段数据正常,第二个字段数据的位置就不对了,是从最后一行数据开始再次添加~我知道问题大概出在我用了ADDNEW~但是其他方法我实在没想到...大家帮帮忙,谢谢
代码大概是这样的
rs.Open "alter table t add team" + CStr(l ) + " int
rs_u.Open "select * from t"
For i = 0 To List1.ListCount - 1
rs_u.AddNew
rs_u.Fields("team" + CStr(l )) = List1.List(i)
rs_u.Update
Next i

解决方案 »

  1.   

    二楼的说得不对吧。你的问题应该是出在这句上:rs_u.Open "select * from t"如果要向记录集中添加数据,应该将它的LockType属性设置为可更新才是,默认是只读的。
    改成这样试试:
    rs_u.Open "select * from t",1,3
      

  2.   

    rs_u.AddNew
    这是新增一条,当然会出现以上情况了,
    把这一句去掉试试。
      

  3.   

    那肯定是這樣了 
    字段1   字段2
    1111
    1111
            2222
            2222
    因為你每增一個字段就AddNew,
    只要第一次AddNew就可以了
    rs.Open "alter table t add team" + CStr(l ) + " int
    rs_u.Open "select * from t"
    For i = 0 To List1.ListCount - 1
    if l=1 then
       rs_u.AddNew
    else
       rs_u.move i
       if rs_u.bof or rs_u.eof then exit for
    end ifrs_u.Fields("team" + CStr(l )) = List1.List(i)
    rs_u.Update
    Next i
      

  4.   

    还有一个问题~就是
    rs.Open "alter table t add team" + CStr(l ) + " int
    rs_u.Open "select * from t"
    For i = 0 To List1.ListCount - 1
    if l=1 then
       rs_u.AddNew
    else
       rs_u.move i
       if rs_u.bof or rs_u.eof then exit for
    end ifrs_u.Fields("team" + CStr(l )) = List1.List(i)
    rs_u.Update
    Next i
    这段代码执行以后,数据库的字段内容不太对,比如输入222,222,111,222
    第一组     第二组
    222         222
    222         222
    111        
    222         111
    是这个样子的~