Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello Friends,

i am using vb.net n sql server2005. i have created views. n i want to connect them to a crystal reports. My views contains parameters. How can i pass them to a view on a button click, so that my view will get parameter and it will connect to a crystal report?

Please help me out
Posted
Comments
[no name] 21-Jul-13 10:59am    
AFAIK, you cannot pass parameters to views.

Hi ,
Try With Stored Procedure or with SQL Functions instead of View.

SQL
CREATE PROCEDURE Test
(
    @testNo INT
) 
AS 
SELECT
    * 
FROM
    test
WHERE 
    testNo=@testNo

For example Function like

CREATE FUNCTION fn_test
(   
    @testNo INT
)
RETURNS TABLE 
AS
RETURN 
(
    SELECT    
    	* 
    FROM    
    	test
    WHERE     
    	testNo=@testNo
)
 
Share this answer
 
1. Just Connect your view on the crystal report,this is just to make the design. don't worry about the WHERE clause(parameter) you can set the data source later on your vb.net code.

Ex.
after you have connected your [view] to the crystal report you can now populate the crystal report like the ff.

VB
Dim Dt As New DataTable
   'Get records
   Private Sub GetRecords()
       Using con As New SqlClient.SqlConnection("YourConnectionString")
           Using com As New SqlClient.SqlCommand("SELECT * FROM [View] WHERE [ID]=@ID;", con)
               com.Parameters.AddWithValue("@ID", "SomeValue")
               Using da As New SqlClient.SqlDataAdapter(com)
                   Dt.Clear()
                   da.Fill(Dt)
               End Using
           End Using
       End Using
   End Sub

   'Set the report
   Private Sub SetReport()
       Dim m_ReportFullPath As String = "Path\of\your\report.rpt"
       Dim MyReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
       MyReport.Load(m_ReportFullPath)
       MyReport.SetDataSource(Dt)
       CrystalReportViewer1.ReportSource = MyReport
   End Sub
 
Share this answer
 
v2

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