我在访问数据库中有以下模块,用于将多条记录连接成一条记录
Option Compare Database
Function Concatenate(pstrSQL As String, _
Optional pstrDelim As String = ", ") _
As String
Dim rs As New ADODB.Recordset
rs.Open pstrSQL, CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic
Dim strConcat As String 'build return string
With rs
If Not .EOF Then
.MoveFirst
Do While Not .EOF
strConcat = strConcat & _
.Fields(0) & pstrDelim
.MoveNext
Loop
End If
.Close
End With
Set rs = Nothing
If Len(strConcat) > 0 Then
strConcat = Left(strConcat, _
Len(strConcat) - Len(pstrDelim))
End If
Concatenate = strConcat
End Function
这是我的查询
SELECT Po_Master.PoNo, Po_Master.PartyName, Po_Master.PoDate, Po_Master.DeliveryDate, Concatenate("SELECT ItemDescription & Chr(9) & Qty FROM Po_Detail WHERE PoNo =" & [PoNo]) AS OrderDetail
FROM Po_Master;
这个查询和函数正在处理访问数据库但是当我在vb.net中调用它时会显示错误oledb异常是unhandeld未定义函数'连接'在表达式中。
Dim ds As New DataSet()
Dim str As String
Dim da As OleDb.OleDbDataAdapter
str = "Select distinct PoNo,PoDate,DeliveryDate,PartyName,OrderDetail from SearchPo"
da = New OleDb.OleDbDataAdapter(str, clsconn.conn)
da.Fill(ds, "SearchPo")
dt = ds.Tables("SearchPo") 'creati
'MyDataGridView1.AutoGenerateColumns = False
dgvSearch1.DataSource = dt
答案 0 :(得分:0)
用户定义的VBA功能仅适用于从Access本身中运行的查询。要在VB.NET应用程序中获得相同的结果,您需要检索子记录并使用VB.NET代码“将它们粘合在一起”。