Click here to Skip to main content
15,915,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am running a crystal report with four different tables using a stored procedure. The select statement in the Stored Procedured is as follows:
SQL
SELECT DISTINCT [tblWHOModelEML].[ActiveIngredient]
		  ,[tblWHOModelEML].[Strength]
          ,[DosageFormRoute]
		  ,[tblWHOATCLevelTwoCodDescrpt].[ATCLevelTwoDescript]
		  ,[tblWHOATCLevelOneCodeDescript].ATCLevelOneDescript
           FROM [dbo].[tblWHOModelEML] LEFT OUTER JOIN [dbo].[tblMCAZ_Approved] ON [dbo].[tblWHOModelEML].[EMLCode] = [dbo].[tblMCAZ_Approved].[EMLCode] INNER JOIN [dbo].[tblWHOATCLevelTwoCodDescrpt] ON [dbo].[tblWHOModelEML].[ATCLevelTwoCode] = [dbo].[tblWHOATCLevelTwoCodDescrpt].[ATCLevelTwoCode] INNER JOIN tblWHOATCLevelOneCodeDescript ON tblWHOModelEML.ATCLevelOneCode = tblWHOATCLevelOneCodeDescript.ATCLevelOneCode
	       WHERE NOT EXISTS (SELECT [dbo].[tblMCAZ_Approved].[ActiveIngredient], [dbo].[tblMCAZ_Approved].[Strength], [dbo].[tblMCAZ_Approved].[DosageForm] FROM [dbo].[tblMCAZ_Approved] WHERE [dbo].[tblWHOModelEML].[EMLCode] = [dbo].[tblMCAZ_Approved].[EMLCode]) 
	       ---AND [tblMCAZ_Approved].[Applicant] Like '%@ApplicantName%' 
		   ORDER BY ActiveIngredient

I have commented out the "AND" which was supposed to further filter the result set using a particular selected Aplicant as this is not working. Can anyone assist me in including this where Applicant LIKE statement into the above SQL statement to make it work. Someone was suggesting use of subqueries and I am blank on this.

Regards.

Chris
Posted
Updated 26-Jun-12 18:12pm
v2

1. Make ApplicationName as the parameter in your storedprocedure.
2. In the crystal reports create a Report parameter and pass this as parameter value to Storedprocedure.

So when the report is generated this value is passed to storedprocedure and the result will be further filtered.
 
Share this answer
 
Comments
Member 8863655 27-Jun-12 6:47am    
Many thanks, Kiran, I am new to programming and Crystal reports, how do I accompllish the second step of passing the parameter value to the Storedprocedure?

Chris
 
Share this answer
 
Comments
Member 8863655 27-Jun-12 8:45am    
Many thanks Kiran

i have the following code in my prompt for parameter values combobox:

Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
Dim myReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
Dim reportPath As String = "C:\Reports\" & "MCAZApprovedWHOEMLReport.rpt"
myReportDocument.Load(reportPath)
myReportDocument.Refresh()
myReportDocument.SetParameterValue("@ApplicantName", appComboBox.Text.Trim())
Dim frm As New frmReportViewer(myReportDocument)
frm.ShowDialog()
End Sub

When i click search, this calls the following code:

Imports CrystalDecisions.CrystalReports.Engine
Imports System.Configuration
Public Class frmReportViewer
Inherits Form
Private m_cryRpt As ReportDocument
Public Sub New(myReportDocument As ReportDocument)
InitializeComponent()
m_cryRpt = myReportDocument
End Sub
Private Sub frmReportViewer_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
DbConnectionInfo.SetConnectionString(ConfigurationSettings.AppSettings(0))
Dim logOnInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim connectionInfo As CrystalDecisions.Shared.ConnectionInfo

For Each Table As Table In m_cryRpt.Database.Tables
logOnInfo = Table.LogOnInfo
connectionInfo = logOnInfo.ConnectionInfo
'Set the connection parameters.
connectionInfo.DatabaseName = DbConnectionInfo.InitialCatalog
connectionInfo.ServerName = DbConnectionInfo.ServerName
If Not DbConnectionInfo.UseIntegratedSecurity Then
connectionInfo.Password = DbConnectionInfo.Password
connectionInfo.UserID = DbConnectionInfo.UserName
Else
connectionInfo.IntegratedSecurity = True
End If
Table.ApplyLogOnInfo(logOnInfo)
Next
myCrystalReportViewer.ReportSource = m_cryRpt
myCrystalReportViewer.Refresh()
End Sub
End Class

I am however getting an exception at the passing parameter stage which says:
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2147352565
Message=Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
Source=CrystalDecisions.ReportAppServer.DataDefModel
StackTrace:
at CrystalDecisions.ReportAppServer.DataDefModel.FieldsClass.get_Item(Int32 Index)
at CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions.get_Item(Int32 index)
at CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions.get_Item(String fieldName)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetParameterValue(String name, Object val)
at MCAZApprovedWHOEMLAnal.frmMain.btnSearch_Click(Object sender, EventArgs e) in C:\Users\Chitemerere\Documents\Visual Studio 2010\Projects\MCAZApprovedWHOEMLAnal\MCAZApprovedWHOEMLAnal\frmMain.vb:line 39
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900