if there is a subreport in you main report , then create a parameter in main report , link that paramtere with the subreport parameter and then again pass that parameter value in code , this will solve you problem..
my subreport name parameter is same like in my main report code :
@no, @code, @user
i use StoredProcedure dbfield to load the data there it is :
No, Name, Address
i'll try to link parameter @no with SP Field No, but it doesn't work. because i can't get another link to
@code and @user and that's the problem. hehe...
younikorne
Member
1 Points
10 Posts
Passing Parameter to Stored Procedure SQL in crystal report with vb.net
Dec 19, 2012 01:24 AM|LINK
Hello,
I have some problem about passing parameter to stored procedure SQL in crystal report with VB.net
So, this is my code :
comd = New SqlCommand
comd.Connection = con
comd.CommandText = "storedprocedure"
comd.CommandType = CommandType.StoredProcedure
Dim SqlParam(2) As SqlParameter
SqlParam(0) = comd.Parameters.Add("@no", SqlDbType.VarChar, 9)
SqlParam(0).Direction = ParameterDirection.Input
SqlParam(0).Value = "xxxxxxxx"
SqlParam(1) = comd.Parameters.Add("@code", SqlDbType.VarChar, 2)
SqlParam(1).Direction = ParameterDirection.Input
SqlParam(1).Value = "xx"
SqlParam(2) = comd.Parameters.Add("@user", SqlDbType.VarChar, 50)
SqlParam(2).Direction = ParameterDirection.Input
SqlParam(2).Value = "user"
Dim MyDA As New SqlDataAdapter
MyDA.SelectCommand = comd
Dim MyDataTable As New DataTable
MyDA.Fill(MyDataTable)
RptDoc.Load(Server.MapPath("~/sample.rpt"))
RptDoc.SetDataSource(MyDataTable)
CrystalReportViewer1.ReportSource = RptDoc
CrystalReportViewer1.DataBind()
My Problem is the parameter can't called in stored procedure, and i have nothing in my report.
So, anyone could help me about my problem ? Please reply with the solved problem.
Thanks.
Best Regards,
Natalia. H
asad.aries
Member
86 Points
37 Posts
Re: Passing Parameter to Stored Procedure SQL in crystal report with vb.net
Dec 19, 2012 04:38 PM|LINK
First of all create report with stored procedures parameters in its parameters list
then
just do the following
RptDoc.Load(Server.MapPath("~/RptETAppr_SP.rpt"))
RptDoc.SetParameterValue("Parameter",value); // here parameters name is the name of parameter in your report which is a stores procedure parameter
// that's it
CrystalReportViewer1.ReportSource = RptDoc
CrystalReportViewer1.DataBind()
younikorne
Member
1 Points
10 Posts
Re: Passing Parameter to Stored Procedure SQL in crystal report with vb.net
Dec 20, 2012 02:41 AM|LINK
Thanks asad.aries for reply my thread.
now my report is definitely succeed to calling that parameter to stored procedure but with another code.
but now, my new problem is i must call that parameter to subreport. haha... and i don't know how the way it is? :p
Did you know about that??
asad.aries
Member
86 Points
37 Posts
Re: Passing Parameter to Stored Procedure SQL in crystal report with vb.net
Dec 20, 2012 06:59 AM|LINK
if there is a subreport in you main report , then create a parameter in main report , link that paramtere with the subreport parameter and then again pass that parameter value in code , this will solve you problem..
younikorne
Member
1 Points
10 Posts
Re: Passing Parameter to Stored Procedure SQL in crystal report with vb.net
Dec 20, 2012 07:55 AM|LINK
Hi asad,
i'll try using subreport links but it doesn't work. huff...
maybe u can give some example code for this??
in vb.net. because i'm using vb.net anyway.
thanks before.
asad.aries
Member
86 Points
37 Posts
Re: Passing Parameter to Stored Procedure SQL in crystal report with vb.net
Dec 20, 2012 05:10 PM|LINK
what is name of your subreport parameter and also is their any dbField in you main report which can be linked to your subreport ?
tell me this then i'll tell u exact sol
younikorne
Member
1 Points
10 Posts
Re: Passing Parameter to Stored Procedure SQL in crystal report with vb.net
Dec 21, 2012 01:00 AM|LINK
my subreport name parameter is same like in my main report code :
@no, @code, @user
i use StoredProcedure dbfield to load the data there it is :
No, Name, Address
i'll try to link parameter @no with SP Field No, but it doesn't work. because i can't get another link to @code and @user and that's the problem. hehe...
so what do u think about??
Thanks for advance.
asad.aries
Member
86 Points
37 Posts
Re: Passing Parameter to Stored Procedure SQL in crystal report with vb.net
Dec 23, 2012 03:34 PM|LINK
i think you are not creating link properly
if @code and @user are not in you main report create them ,
then place subreport in your main report ( your subreport should alse have same parameters )
Creating Links :
On Top select Sub Report
Then Make Sure You Uncheck checkbox saying Select Data In Report based on field ...
instead on the lower left hand side in drop down list select Your Parameter Field(sub report parameter Field to use)
this is how you create a link
then from code pass values to parameters of main report, tou values will be passed to subreport through that link
Hope this would help..
younikorne
Member
1 Points
10 Posts
Re: Passing Parameter to Stored Procedure SQL in crystal report with vb.net
Dec 26, 2012 12:56 AM|LINK
Thanks asad for the answer, ok i will try that...