嗨,我在访问数据库中有以下模块,用于将多条记录连接到一条记录中
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