Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Parameters

Status
Not open for further replies.

nondrinker

Programmer
Jan 23, 2002
53
US
Hello,

I have 2 forms. Form1 and Form2. Form2 has a CrystalReportViewer on it. From Form1 i am passing 2 variables (start date and end date) to Form2.

I am trying to modify the source query of the report at run time, so that it pulls the results within the specified date range only.

This is the code that i am using. varStartDate and varEndDate are the 2 variables i am passing from the Form1.

Right now, I am just testing my code by passing in a hard coded orderID to see if the filtering of my report output works. But eventually i would like to use the 2 date parameters. But right now my filter even for orderid is not working. I am not sure if
i am doing it the right way or not, since this is the first time i am doing anything with Crystal Reports.

Any help in passing the variables to the source of the Crystal Report query will be appreciated.

I developed the report by using the instructions from this link, and it works great, but now i am just trying to pass in parameters to the source query. Right now its pulling the entire Table1 in the output.



************************

Dim rpt As New CrystalReport2
Dim varStartDate As Date
Dim varEndDate As Date


varStartDate = Form1.varStartDate.Value
varEndDate = Form1.varEndDate.Value

myDataAdapter.SelectCommand = New SqlCommand
myDataAdapter.SelectCommand.Connection = myConnection
myDataAdapter.SelectCommand.CommandText = "SELECT * FROM Table1 WHERE QueueInTime BETWEEN '" & varStartDate & "' AND '" & varEndDate & "'"

myDataAdapter.SelectCommand.CommandType = CommandType.Text

Try
myConnection.Open()

myDataAdapter.Fill(myDataSet, "Table1")

rpt.SetDataSource(myDataSet)
rpt.SetParameterValue("OrderID", "442717")
CrystalReportViewer1.ReportSource = rpt

Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

*******************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top