求和问题,执行rs.open后,要把求和后的值,付给文本框!
Private Sub Command1_Click()
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim a As Integer
    
    Set conn = New Connection
    Set rs = New Recordset
    a = Val(Text2.Text)
    
    If Option1.Value = True Then
        conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\db1.mdb;Persist Security Info=False"
        rs.Open "select sum(shuliang) from xiaoshouinfo where yuefen='a'", conn, 1, 3
        
        Text1.Text =*求和后的值*
    End If
End Sub我不知道我的这段代码对不对,请指教!

解决方案 »

  1.   

    Try :
    rs.Open "select sum(shuliang) from xiaoshouinfo where yuefen='"& a & "', conn, 1, 3
            
       Text1.Text =rs.Fields("shuliang").Value  '*求和后的值*
      

  2.   

    还是不行!
    text1.text =rs(0)   提示出错信息为无效使用NULL
    Text1.Text =rs.Fields("shuliang").Value    提示出错信息为在对应所需名称或序数的集合中,未找到项目
      

  3.   

    if not isnull(rs(0)) then
       text1.text =rs(0)
    else
       text1.text =0
    end if
      

  4.   

    Text1.Text = rs(0) & vbNullString
      

  5.   

    有个笨招,救急用:
    你先select查出所有满足条件记录,然后再用循环语句手工实现求和功能
      

  6.   

    两个方法
    1、select isnull(sum(shuliang),0) as t  from xiaoshouinfo where yuefen='a'  得到后直接
        Text1.Text =rs.Fields(0)
    2、If isnull(rs.Fields(0)) then 
           Text1.Text   =0
       else
          Text1.Text    =rs.Fields(0)
       end if