|
-
Sep 12th, 2001, 09:23 AM
#1
Thread Starter
Fanatic Member
Option 1: In a regular class, you can have some method create the recordset of interest and have a public property or method return the recordset object reference (for eg: rs) to the client form. Then set Datagrid1.Datasource = rs at run time in the client form.
Option 2: Use a datasource class. If memory serves me, you can see an example of this if you run the VB wizard for Dataproject and choose the datagrid option with ado class code. The wizard will generate the code.
Ralph
-
Sep 12th, 2001, 09:34 AM
#2
Fanatic Member
I have done Option 1 and have the following for my class
Code:
Option Explicit
Private SQLString As String, CustNo As Variant
Public WithEvents rsTransactions As ADODB.Recordset
Public Sub GetTransactions(CustNo As Variant)
On Error GoTo Error_GetTransactions_Handler
DataMembers.Add "Transactions"
Set rsTransactions = New ADODB.Recordset
SQLString = "SELECT TCD_ABBREV,TO_CHAR(TRN_DATE,'DD-MON-YYYY'),TRN_REFER,TO_CHAR(TRN_CHQNO,'000000MI'), " _
& "LTRIM('0'||(ABS(trn_amount)-trn_amount)/2,'0'), LTRIM('0'||(ABS(trn_amount)+trn_amount)/2,'0'), " _
& "trn_desc "
SQLString = SQLString & "FROM CAST_TRAN, CAST_TRAN_CODE "
SQLString = SQLString & "WHERE TRN_CUSTNO = " & Val(CustNo) & " " _
& "AND SUBSTR(TO_CHAR(TRN_TRAN_CODE,'000000MI'),5,2) = SUBSTR(TO_CHAR(TCD_TRANCODE,'000000MI'),5,2) "
rsTransactions.Open SQLString, conCAS, adOpenStatic, adLockOptimistic
On Error GoTo 0
Exit Sub
Error_GetTransactions_Handler:
End Sub
' Return the Recordset to the data consumer.
Private Sub Class_GetDataMember(DataMember As String, Data As Object)
Select Case DataMember
Case "Transactions"
Set Data = rsTransactions
End Select
End Sub
and on my Form
Code:
Option Explicit
Dim Transactions As clsTransactions
Private Sub Form_Load()
Set Transactions = New clsTransactions
Transactions.GetTransactions (frmCustDetails.CustNo)
DataGrid1.DataMember = "Transactions"
Set DataGrid1.DataSource = Transactions
DataGrid1.Refresh
End Sub
But I keep getting 'The rowset is not bookmarkable' error 7004
Please Help
Mindcrime : )
ICQ 24003332
VB 5.0, VB 6.0 SP5, COM, DCOM, VB.NET Beta 2, Oracle 8
-
Sep 12th, 2001, 11:47 AM
#3
Thread Starter
Fanatic Member
A datagrid can only bind to a bookmarkable recordset. The Static cursor you're using is bookmarkable so that's not the problem. But maybe the embedded functions you're using within the sql string render the recordset not bookmarkable. I suggest testing a simple, plain sql string to see if it works. The rest of the code seems ok.
-
Sep 17th, 2001, 05:45 PM
#4
Fanatic Member
It wasn't the embedded commands in my SQL!!?
I created a new, blank Recordset in my class and populated my SQL RS into the new RS and exposed that to my Data Grid thru the
This seems to work fine!! Long winded, but fine!
I am now wondering if I could CLONE my SQL RS into my new RS and wether that would be bookmarkable?
Mindcrime : )
ICQ 24003332
VB 5.0, VB 6.0 SP5, COM, DCOM, VB.NET Beta 2, Oracle 8
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|