| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 893 人关注过本帖
标题:vb中如何实行access中的dconcat函数的功能
只看楼主 加入收藏
lfhouse
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-3-25
收藏
 问题点数:0 回复次数:0 
vb中如何实行access中的dconcat函数的功能
想在vb中实行以下功能:
表A:
身份证号                  联系电话
4111111111111111               1111
4111111111111111                2222
4111111111111111                3333
用SQL语句将上述记录合并成一条记录,用“,”分隔
4111111111111111                 1111,2222,3333

在access中可以实现
Public Function DCONCAT(sExpr As String, sDomain As String, Optional sCriteria1 As String, Optional sCriteria2 As String, Optional sDelimiter As String)
    On Error GoTo ErrHandler
    Dim rs As New ADODB.Recordset
    Dim sSQL As String
    Dim sResult As String
    sResult = ""
    sSQL = "select " & sExpr & " from (" & sDomain & ")"
    'If sCriteria <> "" Then
        sSQL = sSQL & " where " & sCriteria1 & "'" & sCriteria2 & "'"
    'End If
    rs.Open sSQL, CurrentProject.Connection, 3, 1
    Do While Not rs.EOF
        If sResult <> "" Then
            sResult = sResult & sDelimiter
        End If
        sResult = sResult & rs.Fields(0).Value
        rs.MoveNext
    Loop
    rs.Close
    Set rs = Nothing
    DCONCAT = sResult
    Exit Function
ErrHandler:
    If rs.State <> adStateClosed Then
        rs.Close
    End If
    Set rs = Nothing
    DCONCAT = Err.Number & " : " & Err.Description
End Function

DoCmd.RunSQL  "select * into aaa1 from (select 货品代码,dconcat('单据号码','单据','货品代码=',货品代码,chr(10)) from 单据)"

以上代码在access中可行,3000多条记录,6秒钟执行完毕,但如果在vb中,因为ADO不承认dconcat函数,无法执行,又不想在工程中加载access对象,不知道怎么处理。

实在不行的话,如何在vb中调用access的宏?能写出代码的话就更感激了。
搜索更多相关主题的帖子: access 实行 函数 dconcat 
2010-03-25 10:44
快速回复:vb中如何实行access中的dconcat函数的功能
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013881 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved