好象不对吧,我看如下行不行
Dim colName as String
Dim yy As String
dim rs as new ado.recordset
yy="select sum(dj*ss1) as "&colName& "from sale_ming where xsbh='"&Combo1.text&"'"
set rs=conn.execute yy
text1(0).text=rs(yy)

解决方案 »

  1.   

    colName 没有起到作用呀, 这个我看有点不行,As ...这里应当是汇总的结果呀?
      

  2.   

    yy = "select sum (dj*ssl) as io from sale_ming where xsbh='" & Combo1.Text & "'"
    Conn.Execute yy用Conn.Execute yy执行SQL时不返回记录集,所以text1(0).text=rs(yy)这句就不对了
      

  3.   

    dim rs As New ADODB.Recordset
    ……
    set rs=Conn.Execute yy
      

  4.   

    你对SQL语句中的as的理解有错误,as后面是前面的字段名的别名,并不是你所想象的是“等于”的意思。
      

  5.   

    在SQL语句中AS后应该是字段别名,它是一个字符串。在你的这段代码中,IO是一个整形变量,并且没有赋值。所以在执行该SQL语句时系统不知道该别名的名称。在对记录集的引用时也不对,你不能引用一个记录集的字段名,请试一下下面的代码:
    Dim yy As String
    yy = "select sum (dj*ssl) as sumval from sale_ming where xsbh='" & Combo1.Text & "'"
    dim rst as adodb.recordset
    set rst = Conn.Execute yyText1(0).Text = rst.fields(sumval)如果你要使控件数组对记录集字段进行引用请按下面的代码书写:
    dim i as integer
    for i = 0 to rst.recordcoun
        text (i).text = rst.fields(sumval)
        rst.movenext
    next
      

  6.   

    set rst =conn.execute yy
    这句是不是有问题呀
      

  7.   

    你可以这样试一试:
    dim rs as adodb.recordset
    yy="select sum(dj*ss1) as column1 from sale_ming where xsbh='"&Combo1.text&"'"
    set rs=connectionName.execute(yy)
    text1(0).text=rs.fields("column1").value
      

  8.   

    Dim yy As String
    Dim xRec As daodb.recordset
    yy = "select sum (dj*ssl) from sale_ming where xsbh='" & Combo1.Text & "'"
    set xRec=Conn.OpenRecordSet(yy,dbopendynaset)
    Text1(0).Text = xRec.fields(0)
    set xRec=nothing
      

  9.   

    SQL这样写:
    "select sum (dj*ssl) as io from sale_ming where xsbh='" & trim(Combo1.Text) & "'"
      

  10.   

    当然as之后的是读取字段的自定义名,你把它的值取出是没用的啊,只能使用rs啊
      

  11.   

    "select sum (dj*ssl) as io from sale_ming where xsbh='" & trim(Combo1.Text) & "'"
    这个xsbh字段是什么类型的?字符加'',long等不加,日期datevalue('')
      

  12.   

    我还是用了最笨的办法
    Rs_3.Open "select dj,ssl from sale_ming where xsbh='" & Combo1.Text & "'", Conn, adOpenStatic, adLockBatchOptimistic
    yy = 0
    Do While Not Rs_3.EOF
    yy = yy + Rs_3.Fields(0) * Rs_3.Fields(1)
    Rs_3.MoveNext
    Loop
    Text1(0).Text = Format(yy, "0.00")
    Rs_3.Close
      

  13.   

    我还是用了最笨的办法Rs_3.Open "select dj,ssl from sale_ming where xsbh='" & Combo1.Text & "'", Conn, adOpenStatic, adLockBatchOptimistic
    yy = 0
    Do While Not Rs_3.EOF
    yy = yy + Rs_3.Fields(0) * Rs_3.Fields(1)
    Rs_3.MoveNext
    Loop
    Text1(0).Text = Format(yy, "0.00")
    Rs_3.Close
      

  14.   

    Dim yy As String
    dim rst as adodb.recordset
    Dim io As Integer
    yy = "select sum (dj*ssl) as uvalue from sale_ming where xsbh='" & Combo1.Text & "'"
    set rst=Conn.Execute(yy)
    io=val(rst("uvalue")&"")
    Text1(0).Text = io
    =====================
    www.myvc.net
    编程技术论坛欢迎你的加盟!