用ADODC连到了VB,在VB上插入,销售信息表和商品进货表显示键列信息不足或不正确。而商品信息表则显示多步操作产生错误。请问是怎么回事啊?
在sql上用企业管理器和查询分析器插入一切正常。

解决方案 »

  1.   

    进货单ID是主键,自动递增,总价是自己算,进货日期也是自己得出
    脚本应该没问题,我6个表的脚本都一样,就是改了连接部分,其他那些没有外键的表添加就正常。这个是进货信息表的脚本Private Sub cmd_geng_Click()
    Adodc1.Recordset.Fields("数量") = Trim(Text2.Text)
    Adodc1.Recordset.Fields("单价") = Trim(Text4.Text)
    Adodc1.Recordset.Fields("经销商ID") = Trim(Text6.Text)
    Adodc1.Recordset.Fields("商品ID") = Trim(Text8.Text)
    Adodc1.Recordset.Fields("备注") = Trim(Text7.Text)
    If cmd_geng.Caption = "保存" Then
    MsgBox "保存成功"
    cmd_geng.Caption = "更新"
    Else
    MsgBox "更新成功"
    End If
    Adodc1.Recordset.Update
    cmd_tian.Enabled = True
    cmd_shan.Enabled = True
    cmd_qu.Enabled = False
    End SubPrivate Sub cmd_qu_Click()
    Adodc1.Recordset.CancelUpdate
    cmd_tian.Enabled = True
    cmd_shan.Enabled = True
    cmd_qu.Enabled = False
    cmd_geng.Caption = "更新"
    End SubPrivate Sub cmd_shan_Click()
    Dim res As Integer
    res = MsgBox("确定要删除此行信息吗?", vbExclamation + vbYesNo + vbDefaultButton2)
    If res = vbYes Then
    Adodc1.Recordset.Delete
    Adodc1.Recordset.MoveNext
    If Adodc1.Recordset.EOF = True Then
    Adodc1.Recordset.MoveLast
    End If
    End If
    End SubPrivate Sub cmd_tian_Click()
    Adodc1.Recordset.AddNew
    cmd_tian.Enabled = False
    cmd_shan.Enabled = False
    cmd_qu.Enabled = True
    cmd_geng.Caption = "保存"
    End SubPrivate Sub Command10_Click()
    Me.Hide
    Form2.Show
    End SubPrivate Sub Command5_Click()
    End
    End SubPrivate Sub Form_Load()
    cmd_qu.Enabled = False
    End Sub
      

  2.   

    既然查询分析器插入是正常的,那估计是adodc的问题
    建议去vb版问问吧
      

  3.   

    会不会某个表单的name重复了 比如两个text4 嘿嘿
      

  4.   

    参考:
    http://wenda.tianya.cn/wenda/thread?tid=6c2856eed0f5fa0a
    http://blog.sina.com.cn/s/blog_4cd978f90100lx0u.html
    http://www.alixixi.com/program/a/2009122359357.shtml
      

  5.   

    执行一下 TRUNCATE TABLE tablename 命令.
      

  6.   

    /*
    declare @table table (id int identity(1,1),col varchar(1))
    insert into @table
    select 5,'a' union all
    select 6,'b' union all
    select 9,'c'--先取消自增列
    */
    declare @table table (id int,col varchar(1))
    insert into @table
    select 5,'a' union all
    select 6,'b' union all
    select 9,'c'
    declare @i int
    set @i=0
    update @table
    set @i=id=@i+1select * from @table
    /*
    id          col
    ----------- ----
    1           a
    2           b
    3           c
    */