hello!
please check this code , it is in vb.net but may be this will give you any idea :)
Sub Purchase_VenderWise()
With Frm_ListOfPurchaseHistory
.rpt_PurchaseHistory1.DataSourceConnections(0).SetConnection(myCrServerName, myCrDatabaseName, myCRUserName, myCRUserPassword)
.CrystalReportViewer1.SelectionFormula = "{PurchaseHead.VenderID}=" & Val(Me.txtinput.Text)
.CrystalReportViewer1.SelectionFormula = "{PurchaseHead.PurchaseDate} in DateTime(" & Me.dtpfrom.Value.Year & "," & Me.dtpfrom.Value.Month & "," & Me.dtpfrom.Value.Day & ") to DateTime(" & Me.dtpto.Value.Year & "," & Me.dtpto.Value.Month & "," & Me.dtpto.Value.Day & ")" & " and {PurchaseHead.VenderID}=" & Val(Me.txtinput.Text)
.Show()
End With
Regards