首先说明我的题目:大概就是要做一个库存管理,其中有两张表,一张是product放产品的型号
和当前的数量,还有一张是pinput表,是放存入仓库的记录。其中有个控件ADO空间ADOBC2连接的是表product 
然后下面的这段语句我不知道怎么写,反正一直有问题,
Adodc2.Recordset.DataSource = "select amount from product where id=val(DataCombo1.Text)"
Adodc2.Recordset.Fields("amount").Value = Val(Text1.Text) + Adodc2.Recordset.Fields("amount").Value
Adodc2.Recordset.Update
这段话的意思就是在产品(product)表中把入库产品的数量和原来产品的数量相加,放入之后的产品(product)表中,
其中amount是product表中产品数量的字段,DataCombo1.Text这是控件和product的ID字段相连的,
text1输入的是入库产品的数量,这些估计问题不大。
我想主要的问题是出在上面那里的第一句话上,Adodc2.Recordset.DataSource 这里要用的方法我估计
也有问题,错误的提示:“未找到方法和数据成员”。希望兄弟们帮忙看看......

解决方案 »

  1.   

    Adodc2.Recordset.DataSource = "select amount=Val(Text1.Text) +amount from product where id=val(DataCombo1.Text)"
      

  2.   

    private sub subName()
    on error goto err_handleDim cn As ADODB.Connection
    Set cn = New ADODB.Connection
    cn.ConnectionString = "这里写进连接字串"
    cn.Open
    cn.Execute "update product set amount=" & text1 & " where id=" DataCombo1.Text 
    cn.close
    set cn = nothing
    exit subErr_Handle
    if not cn is nothing then set cn=nothingmsgbox "操作失败"end sub
     
      

  3.   

    private sub subName()
    on error goto err_handleDim cn As ADODB.Connection
    Set cn = New ADODB.Connection
    cn.ConnectionString = "这里写进连接字串"
    cn.Open
    '下面这句刚才写漏了一点:
    cn.Execute "update product set amount=" & text1 & " where id=" & DataCombo1.Text 
    cn.close
    set cn = nothing
    msgbox "操作成功"
    exit subErr_Handle
    if not cn is nothing then set cn=nothingmsgbox "操作失败"end sub
      

  4.   

    private sub subName()
    on error goto err_handleDim cn As ADODB.Connection
    Set cn = New ADODB.Connection
    cn.ConnectionString = "这里写进连接字串"
    cn.Open
    '下面这句刚才写漏了一点:
    cn.Execute "update product set amount=" & text1 & " where id=" & DataCombo1.Text 
    cn.close
    set cn = nothing
    msgbox "操作成功"
    exit subErr_Handle: '这里刚才也漏了,比较粗心,不好意思。
    if not cn is nothing then set cn=nothing
    msgbox "操作失败"end sub
      

  5.   

    1楼回复的大概有点理解错误了,
    Adodc2.Recordset.DataSource = "select amount from product where id=val(DataCombo1.Text)"
    这句话我是找到那个id等于我输入DataCombo1的那个记录集的产品数量(amount)
    至于让两个数相加是在下面的这句话实现
    Adodc2.Recordset.Fields("amount").Value = Val(Text1.Text) + Adodc2.Recordset.Fields("amount").Value
      

  6.   

    "Access" 
            Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbpath & ";Persist Security Info=False"
    "SQL"
            Conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & useId & ";pwd=" & pd1 & ";Data Source=" & serverName
      

  7.   

    Adodc2.Recordset.DataSource = "select amount from product where id=val(DataCombo1.Text)"
    改为:Adodc2.DataSource = "select amount from product where id=val(DataCombo1.Text)"
      

  8.   

    回复: helanshan(C++)
    我开始就是 Adodc2.DataSource 这样的
    可是有一个非常奇怪的问题,每次无论怎么样,我修改的都是数据库中第一条数据的内容
    真的是奇怪,主要是我开始在ADODC2中定义了它的datasource为一张表,不知道这样有没有问题,
    然后我有搞了一个ADODC3,然后它的datasource没有设置,通过上面的语句,还是不行