Private Sub Form_Load()
Dim rs1 As ADODB.RecordSet
Set rs1 = Getrs
DataGrid1.DataSource = rs1
End Sub
Private Function Getrs() As ADODB.RecordSet
Dim conn As ADODB.Connection
Dim rs As ADODB.RecordSet
Dim strConn As String
Dim strSQL As String
Set conn = New ADODB.Connection
Set rs = New ADODB.RecordSet
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Sourcece=C:\DB.mdb"
conn.Open strConn
strSQL = "SELECT * FROM Table"
rs.CursorLocation = adUseClient
rs.Open strSQL, conn, adOpenKeyset, adLockBatchOptimistic
Set Getrs = rs
conn.Close
rs.close
Set conn=Nothing
Set rs = Nothing
End Function
可是當我執行到Form_load中的Set DataGrid1.DataSource=rs1
就會出現,參數為不可接受了類型..
可是如果我把Function Getrs內的程式碼(除了rs.close和...)再去掉Form_Load中的再將DataGrid1.DataSource=rs卻可執行..
另外請教一點,如果我在Form_Load中,把rs.CursorLoaction=adUseServer那最後傳回來的rs1會是adUseClient還是adUseServer呢(在Form_Load中已先將rs1設成adUseServer再去呼叫Function Getrs但是Getrs中所設定rs為adUseClient那傳回值是adUseClient但那rs1最後是..?)
謝謝