Public Function myRSVal(mysql As String, mycon As String, myrscol As Integer) As String On Error GoTo myrsvalERR Dim myRs As New ADODB.Recordset Dim oCon As New ADODB.Connection
oCon.ConnectionString = mycon oCon.Open oCon.CommandTimeout = 600 myRs.Open mysql, oCon, adOpenStatic If myRs.EOF = False Then myRSVal = TurnNull(myRs(myrscol)) Else myRSVal = "" End If Set myRs = Nothing oCon.Close Exit Function myrsvalERR: On Error Resume Next myRSVal = "" 'oCon.Close Set myRs = Nothing Set oCon = Nothing myRSVal = "" End Function
Public Function TurnNull(ByVal astr As Variant) As String If Not IsNull(astr) Then TurnNull = Trim(astr) Else TurnNull = "" End If End Function看不懂就别问了
On Error GoTo myrsvalERR
Dim myRs As New ADODB.Recordset
Dim oCon As New ADODB.Connection
oCon.ConnectionString = mycon
oCon.Open
oCon.CommandTimeout = 600
myRs.Open mysql, oCon, adOpenStatic
If myRs.EOF = False Then
myRSVal = TurnNull(myRs(myrscol))
Else
myRSVal = ""
End If
Set myRs = Nothing
oCon.Close
Exit Function
myrsvalERR:
On Error Resume Next
myRSVal = ""
'oCon.Close
Set myRs = Nothing
Set oCon = Nothing
myRSVal = ""
End Function
If Not IsNull(astr) Then
TurnNull = Trim(astr)
Else
TurnNull = ""
End If
End Function看不懂就别问了