ADO PARAMETERIZED QUERIES AND DATA REPORT - project.zip (0/1) 
Author Message
 ADO PARAMETERIZED QUERIES AND DATA REPORT - project.zip (0/1)

Just thought I would drop a note to those struggling with
parameterized queries using VB6, the DataConnectioDesigner and
DataReports. Below is some sample code that works, the table I used
has few fields and this is simple at best. I use the
ConnectionDesigner and just insert the good old "?" into the variable
you want to pass in the query.

Here is the form code:

Dim rs As Recordset
Private Sub Command1_Click()
Dim rs As Recordset, count As Integer 'just fooling around here for
debugging
DataEnvironment1.Commands.Item("command1").Parameters(0).Value = 4
Set rs = DataEnvironment1.Commands.Item("command1").Execute()
DataEnvironment1.rsCommand1.Open
count = DataEnvironment1.rsCommand1.RecordCount
DataEnvironment1.rsCommand1.Close
End Sub

Private Sub Command2_Click()
DataReport1.Show 'show the report
End Sub

Private Sub Form_Load()
List1.AddItem 1 'load simple listbox with values
List1.AddItem 2
List1.AddItem 3
List1.AddItem 4

End Sub
Private Sub List1_Click()
rsValue = Val(List1.Text) 'set the value of the public variable
'used to set the parameter
End Sub

' The only thing in a module is the rsValue declared as a Public
Variable

Here is the DataReport's Initialize Event:

Private Sub DataReport_Initialize()
Dim rs As Recordset, count As Integer
On Error GoTo err:

DataEnvironment1.Commands.Item("command1").Parameters(0).Value =
rsValue
Set rs = DataEnvironment1.Commands.Item("command1").Execute()
DataEnvironment1.rsCommand1.Open
Exit Sub
err:
DataEnvironment1.Commands.Item("command1").Parameters(0).Value =
rsValue
Set rs = DataEnvironment1.Commands.Item("command1").Execute()
DataEnvironment1.rsCommand1.Close

End Sub

Here is the SQL Query I use:

SELECT Incident_ID, Section, Acuity_Level, Incident_Type FROM
Incidents WHERE (Acuity_Level = ?)

' Again this is just barebones to help folks struggling with this, as
I was... Henry



Wed, 09 May 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. No data returned using Access parameterized query and ADO

2. Parameterized access query, and ADO

3. The SOLUTION to a question I posted on ADO parameterized queries

4. Cannot get ADO in VB to recognize a Access parameterized query as stored procedure

5. sp_executesql and ADO parameterized queries

6. howto do a parameterized query to Access with ADO

7. Cannot get ADO in VB to recognize a Access parameterized query as stored procedure

8. parameterized Query/Report

9. Reports+parameterized queries in VB6

10. Crystal Reports Parameterized Query

11. use parameterized query in Crystal Report

12. Any Interest in Crystal Report Viewer which support Parameterized Queries

 

 
Powered by phpBB® Forum Software