Function GetRs(ByVal connstr As String, ByVal FieldStr As String, ByVal TableStr As String, ByVal wherestr As String, ByVal orderstr As String, ByVal sortstr As String) As Object
Dim conn As New ADODB.Connection
Dim GetRs1 As New ADODB.Recordset
Dim sql As String
On Error GoTo errhandler
conn.Open connstr
If FieldStr = "" Then FieldStr = "*"
sql = "select " & FieldStr & " from " & TableStr
If wherestr <> "" Then
sql = sql & " where " & wherestr
End If
If orderstr <> "" Then
If sortstr <> "desc" Then sortstr = "asc"
sql = sql & "order by " & orderstr & sortstr
End If
GetRs1.Open sql, conn, 1, 3
Set GetRs = GetRs1
Exit Function
errhandler:
MsgBox Err.Description
End Function
以上为组件haha.xixi
以下为调用
Private Sub Command1_Click()
Dim connstr As String
connstr = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Pwd=aaa;Initial Catalog=bbb;Data Source=ccc;Locale Identifier=2052;Connect Timeout=15;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096"
Dim rs As Object
Dim TestObject As Object
Set TestObject = CreateObject("haha.xixi")
Set rs = TestObject.GetRs(connstr, "", "TblMembership", "", "", "")
MsgBox rs.RecordCount
rs.close
set rs=nothing
set TestObject=nothing
End Sub