怎樣將Access數據庫中一個字段匯總,然後將結果傅給一個窗口中的一個文本框!

解决方案 »

  1.   

    dim conn as new adodb.connection
    dim rs as new adodb.recordset
    dim strsql   as stringconn.conntionstring="..."    '与数据库的连接语句
    conn.open
    strsql="select sum(aa) as aa from tablename"
    if rs.state=adstateopen then rs.close
    rs.open strsql,conn,adopenkeyset,adlockreadonly
    if rs.recordcount>0 then
        text1.text=rs!aa
    else
        text1.text=""
    end if
    rs.close
    conn.close
      

  2.   

    首先用ADO连接到Access数据库,语句写法为:
    Con.ConnectionString="Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=数据
    库名"
    然后打开连接:Con.open
    再后执行如下查询语句:
    Recordset.open "Select sum(要统计的字段名) as totalvalue from [表名]", Con, adOpenStatic, adLockReadOnly, adcmdText再把结果值传给文本框(这里保留两位小数)
    Text1.text=format(Recordset!totalvalue,"0.00")