我提交一条记录在DLL里完成查询,请问完成后如何返回数据集到原窗体?(有代码)dll里:Public Sub SQLADD(ByVal CONN As ADODB.Connection, _
ByVal TABLEname, Optional ByVal STRWHERE As String)
Dim STR
Set RS = New ADODB.Recordset
RS.CursorType = adOpenKeyset
RS.LockType = adLockOptimistic
STR = "SELECT * FROM" & " " & TABLEnaME
RS.Open STR, CONN
If Not RS.EOF Then
STRWHERE = RS
End If
RS.Close
Set RS = Nothing
End Sub
程序的FORM:
Private Sub Command1_Click()
Dim hh As New ClsSQL
hh.SQLADD con, "TBL_SUBAWB", ""
End Sub如何返回数据集 RS ?
ByVal TABLEname, Optional ByVal STRWHERE As String)
Dim STR
Set RS = New ADODB.Recordset
RS.CursorType = adOpenKeyset
RS.LockType = adLockOptimistic
STR = "SELECT * FROM" & " " & TABLEnaME
RS.Open STR, CONN
If Not RS.EOF Then
STRWHERE = RS
End If
RS.Close
Set RS = Nothing
End Sub
程序的FORM:
Private Sub Command1_Click()
Dim hh As New ClsSQL
hh.SQLADD con, "TBL_SUBAWB", ""
End Sub如何返回数据集 RS ?
ByVal TABLEname, Optional ByVal STRWHERE As String) as adodb.recordset
Dim STR
Set RS = New ADODB.Recordset
RS.CursorType = adOpenKeyset
RS.LockType = adLockOptimistic
STR = "SELECT * FROM" & " " & TABLEnaME
RS.Open STR, CONN
If Not RS.EOF Then
STRWHERE = RS
set SQLADD = RS
End If RS.Close
Set RS = NothingEnd function
Dim hh As New Class1
hh.sqladd con, "bbsconfig", "hh"
MsgBox sqladd.Fields(0).Value
End Sub
得不到 sqladd.Fields(0).Value 的值啊
將過程改為Function,再加上"As ADODB.Recordset",然後用SQLADD替換RS就可以了.
ByVal TABLEname, Optional ByVal STRWHERE As String) as adodb.recordset
Dim STR
Set RS = New ADODB.Recordset
RS.CursorType = adOpenKeyset
RS.LockType = adLockOptimistic
STR = "SELECT * FROM" & " " & TABLEnaME
RS.Open STR, CONN
If Not RS.EOF Then
STRWHERE = RS
set SQLADD = RS
End If RS.Close
Set RS = NothingEnd function
调用:
dim rst as New ADODB.Recordset
set rst=SQLADD(数据库设置,路径,文件名等)set datagri1.datasource=rst
但还有个问题,如我要在查找数据库后返回某一个值同,代码该如何写?如下:STRWHERE = rs.Fields(0).Value然后:msgbox STRWHERE 好象不行啊