Showing posts with label parameters. Show all posts
Showing posts with label parameters. Show all posts

Sunday, February 19, 2012

Accessing Stored Procedure parameters through XSD

Hi All,

I have created a stored procedure (in SQL Server 2005 - Developer) with input and output parameters. Please somebody let me know how I can call this store procedure from code behind using TableAdapter i.e. through XSD.

Thanks,

Long Live Microsoft ;)

You can start from here:Working with a Typed DataSet, and this tutorial should help:Working with Data in ASP.NET 2.0 :: Sorting Custom Paged Data. However if you just want to call the stored procedure from .net application, it should be?much easier to use SqlCommand/SqlDataAdapter.|||

Thanks for the response,

I have created a store procedure

CREATEPROCEDURE [GetUserDetails]

(

@.paramUserID INT ,

@.paramName VARCHAR(50) OUTPUT,

@.paramEmail VARCHAR(150) OUTPUT,

@.paramDOB DATETIME OUTPUT

…

…

--here more parameters will come

)

AS

BEGIN

SELECT

@.paramName = [Name]

,@.paramEmail =Email

,@.paramDOB = [DOB]

FROM

[Users]

WHERE

[UserID] = @.paramUserID

--more sql script will be here for additional parameters

END

I know we can easily call the strored procedure by using sqlcommand and adding sqlparameters etc.

But I have create the Dataset(xsd) in my application and I need to channel all my data operations through this.

I'v create a tableadapter for 'user' table and I need to add a query using existing stored proc 'GetUserDetails'. This procedure will expand cause I need to add another functionalities to it.

Please could you explaing how can I do this.

|||Well it's not a short explanation,?and?I?think?it's?better?to?follow?some?tutorial:

Working with Data in ASP.NET 2.0 :: Creating a Data Access Layer|||

Thanks Iori_Jay

Finally Igot the solution, and its working.

Myproblem was:

Executing stored procedure with inputand output parameters through XSD.

Stored Procedure

Posted earlier

User.xsd

TableAdapter: UserDetailsTableAdapter

Query: GetUserDetails(@.paramUserID,@.paramName, @.paramEmail, @.paramDOB)

Code to access outputparameter values

UsersTableAdapters.UserDetailsTableAdapterssobjGetUser =new UsersTableAdapters.UserDetailsTableAdapter();

String strName ="",

strEmail ="";

DateTime? dtDOB =DateTime.Now;

objGetUser.GetUserDetails(3/*userid*/, ref strName,refstrEmail,ref dtDOB);

Response.Write("<h3>UserDetails</h3>");

Response.Write("<strong>Name:</strong> " +strName);

Response.Write("<br/> <strong>Email:</strong>" + strEmail);

Response.Write("<br/><strong>DOB:</strong> " + dtDOB.ToString());


Although "System.String" and "string" are reference typesit showed error when "string" is used, so I used "String" instead of "string".

Added "?" to avail the reference property of value type "Datetime".

Sunday, February 12, 2012

Accessing report through URL not getting prompted for parameters

I'm accessing my report through a URL:
http://reportserver/ReportServer?/Folder/ReportName&rs:Command=Render&rs:Format=CSV&rc:Parameters=true

I am getting an error: This report requires a default or user-defined
value for the report parameter 'beg_dt'. To run or subscribe to this
report, you must provide a parameter value.
(rsReportParameterValueNotSet) Get Online Help

I do not want to pass the report parameters (to and from dates) through
the URL. I want the dates to be entered by the user running the
report. If I enter default parameters in Report Manager I am not prompted
for the dates.

This will depend on what render format you want to specify in the URL. For rs:format=CSV, you will either need to have default parameters or specify in the URL. You cannot specify parameters to that format post render.

If you are using rs:format=HTML4.0 in the report viewer(report manager or report server), you do not have to specify the parameters. You should be prompted if the parameters are set to prompt with no default values. If you have default values, the report will execute.

Accessing report parameters from code module can it be done?

I'm trying to get around a problem where my client wants to have totals from
each grouping in the report table displayed at the top of the report body
above the report table. It's easy to see why you can't just grab values from
the grouping footers and place them elsewhere. I had an idea to create some
report parameters and as the report is being rendered, run some custom code
that evaluates the field I'm trying to total and modifies the report
parameter I created for that specific total. Then I could use the report
parameter to display that specific total.
The problems with this are.. It seems that if I pass the parameter object
into the custom code function, it becomes read-only. Next, how would I be
able to tell the textbox that will show the total to wait to render until the
END of the report rendering. Lots of problems to try to overcome.
Basically, I need to take the value of a total in a subgroup (there are like
7 subgroups, so 7 different totals -- I can already take the ENTIRE report
total, but that's not what's neded) and copy it to a textbox either in the
report body ABOVE the report table.
Thanks for any tips.
--
Ken Fayal
Raptor Development Corp.I thought about this some and the only thing I can come up with is to have a
second dataset that has the same grouping and sums and reference the second
dataset at the top of the report. (By grouping I mean in SQL, not in RS).
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Ken Fayal" <ken@.raptordev.com.spamfree> wrote in message
news:5E4D812B-4868-44A7-BD79-F9E75C748F5C@.microsoft.com...
> I'm trying to get around a problem where my client wants to have totals
from
> each grouping in the report table displayed at the top of the report body
> above the report table. It's easy to see why you can't just grab values
from
> the grouping footers and place them elsewhere. I had an idea to create
some
> report parameters and as the report is being rendered, run some custom
code
> that evaluates the field I'm trying to total and modifies the report
> parameter I created for that specific total. Then I could use the report
> parameter to display that specific total.
> The problems with this are.. It seems that if I pass the parameter object
> into the custom code function, it becomes read-only. Next, how would I be
> able to tell the textbox that will show the total to wait to render until
the
> END of the report rendering. Lots of problems to try to overcome.
> Basically, I need to take the value of a total in a subgroup (there are
like
> 7 subgroups, so 7 different totals -- I can already take the ENTIRE report
> total, but that's not what's neded) and copy it to a textbox either in
the
> report body ABOVE the report table.
> Thanks for any tips.
> --
> Ken Fayal
> Raptor Development Corp.
>|||Bruce,
Thanks. What I ended up doing was create a subreport and put that at the
top. It works great. I guess I could have created another dataset, but he
subreport was easy because I had to use the same subreport in many other
reports.
"Bruce L-C [MVP]" wrote:
> I thought about this some and the only thing I can come up with is to have a
> second dataset that has the same grouping and sums and reference the second
> dataset at the top of the report. (By grouping I mean in SQL, not in RS).
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
>
> "Ken Fayal" <ken@.raptordev.com.spamfree> wrote in message
> news:5E4D812B-4868-44A7-BD79-F9E75C748F5C@.microsoft.com...
> > I'm trying to get around a problem where my client wants to have totals
> from
> > each grouping in the report table displayed at the top of the report body
> > above the report table. It's easy to see why you can't just grab values
> from
> > the grouping footers and place them elsewhere. I had an idea to create
> some
> > report parameters and as the report is being rendered, run some custom
> code
> > that evaluates the field I'm trying to total and modifies the report
> > parameter I created for that specific total. Then I could use the report
> > parameter to display that specific total.
> >
> > The problems with this are.. It seems that if I pass the parameter object
> > into the custom code function, it becomes read-only. Next, how would I be
> > able to tell the textbox that will show the total to wait to render until
> the
> > END of the report rendering. Lots of problems to try to overcome.
> >
> > Basically, I need to take the value of a total in a subgroup (there are
> like
> > 7 subgroups, so 7 different totals -- I can already take the ENTIRE report
> > total, but that's not what's neded) and copy it to a textbox either in
> the
> > report body ABOVE the report table.
> >
> > Thanks for any tips.
> >
> > --
> > Ken Fayal
> > Raptor Development Corp.
> >
>
>

Accessing Report Parameters Class through Web Service

I am using ASP .NET along to render my reports. I've extended the web
service class such that I specify the report folder, and I get all
reports and their respective parameters. I then dyncamically create
the controls (such as datepicker, textbox, etc...) based on the
Parameter Name, and Type. The drop down list is the one giving me the
hardest time though.
My problem is this: I have a Report with 3 parameters. The first 2
are dates. I can retrive all info on them just fine. The name,
prompt, and type (datetime). The third parameter (AppUserKey) however
is a dropdown list of all the users. I wrote a stored procedure that
does this called spGetAppUsers. Here is the structure of this
parameter as per the RDL file:
</ReportParameters>
...
...
<ReportParameter Name="AppUserKey">
<DataType>Integer</DataType>
<DefaultValue>
<DataSetReference>
<DataSetName>spGetAppUsers</DataSetName>
<ValueField>AppUserKey</ValueField>
</DataSetReference>
</DefaultValue>
<Prompt>AppUserKey</Prompt>
<ValidValues>
<DataSetReference>
<DataSetName>spGetAppUsers</DataSetName>
<ValueField>AppUserKey</ValueField>
<LabelField>AppUserName</LabelField>
</DataSetReference>
</ValidValues>
</ReportParameter>
</ReportParameters>
I can get the Name, and even from the ValidValues, the ValueField and
LabelField, however, I want the <DataSetName> entry.
This is so that after I dynamically create the drop down list, I'm
able to populate it via the stored procedure. Recall that the
ReportParameter class is defined here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSPROG/htm/rsp_ref_soapapi_ir_5zec.asp
ReportParameter::QueryParameter is a boolean property. Doesn't
actually return the name. Just whether or not you are using a query.
ReportParameter::DefaultValues is a string but is empty, since the
report hasn't executed the stored procedure (makes sense).
I want this to be a generic solution. Hence all this trouble to get
all the "givens" from the Report, and to reconstruct it in ASP .NET.
I need that DataSetName!!! :-S
Any help is appreciated.
Thanks for your time,
RoyThere are 2 ways to do what I want:
1. Instead of trying to get the stored procedure of my query based
parameter, I should've set forRendering = True in my
GetReportParameters function. That will actually return the query
based parameter set. Then I can populate the drop down list with that.
2. Load the .RDL (report definition in XML) in memory and use XPATH to
get the name of the parameter:
Dim reportDefinition As Byte() = Nothing
Dim doc As New System.Xml.XmlDocument
Try
reportDefinition = rs.GetReportDefinition(ReportsFolder &
strReportName)
Dim stream As New MemoryStream(reportDefinition)
doc.Load(stream)
In this scenario, assuming you have forRedering=True or False, you
still need to know the name of the parameter. So you'ld probably get
then name of the parameter and then check the value of QueryParameter
to see if it's true.
Then base your XPATH query on the following XML:
"/ReportParameter/ValidValues/DataSetReference/DataSetName[@.text]"
Or something similar. I forget. The above is proabably wrong and
could be written in a million different ways.
<ReportParameter Name="AppUserKey">
<DataType>Integer</DataType>
<DefaultValue>
<DataSetReference>
<DataSetName>spGetAppUsers</DataSetName>
<ValueField>AppUserKey</ValueField>
</DataSetReference>
</DefaultValue>
<Prompt>AppUserKey</Prompt>
<ValidValues>
<DataSetReference>
<DataSetName>spGetAppUsers</DataSetName>
<ValueField>AppUserKey</ValueField>
<LabelField>AppUserName</LabelField>
</DataSetReference>
</ValidValues>
</ReportParameter>
</ReportParameters>
Roy Assaly wrote:
> I am using ASP .NET along to render my reports. I've extended the
web
> service class such that I specify the report folder, and I get all
> reports and their respective parameters. I then dyncamically create
> the controls (such as datepicker, textbox, etc...) based on the
> Parameter Name, and Type. The drop down list is the one giving me
the
> hardest time though.
> My problem is this: I have a Report with 3 parameters. The first 2
> are dates. I can retrive all info on them just fine. The name,
> prompt, and type (datetime). The third parameter (AppUserKey)
however
> is a dropdown list of all the users. I wrote a stored procedure that
> does this called spGetAppUsers. Here is the structure of this
> parameter as per the RDL file:
> </ReportParameters>
> ...
> ...
> <ReportParameter Name="AppUserKey">
> <DataType>Integer</DataType>
> <DefaultValue>
> <DataSetReference>
> <DataSetName>spGetAppUsers</DataSetName>
> <ValueField>AppUserKey</ValueField>
> </DataSetReference>
> </DefaultValue>
> <Prompt>AppUserKey</Prompt>
> <ValidValues>
> <DataSetReference>
> <DataSetName>spGetAppUsers</DataSetName>
> <ValueField>AppUserKey</ValueField>
> <LabelField>AppUserName</LabelField>
> </DataSetReference>
> </ValidValues>
> </ReportParameter>
> </ReportParameters>
> I can get the Name, and even from the ValidValues, the ValueField and
> LabelField, however, I want the <DataSetName> entry.
> This is so that after I dynamically create the drop down list, I'm
> able to populate it via the stored procedure. Recall that the
> ReportParameter class is defined here:
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSPROG/htm/rsp_ref_soapapi_ir_5zec.asp
> ReportParameter::QueryParameter is a boolean property. Doesn't
> actually return the name. Just whether or not you are using a query.
> ReportParameter::DefaultValues is a string but is empty, since the
> report hasn't executed the stored procedure (makes sense).
> I want this to be a generic solution. Hence all this trouble to get
> all the "givens" from the Report, and to reconstruct it in ASP .NET.
> I need that DataSetName!!! :-S
> Any help is appreciated.
> Thanks for your time,
> Roy

Accessing Queries in sqlDataAdapter

Hello Dears;

I have an SqlDataAdapter which contains may queries. One query contians 3 query parameters as follows:

SELECT SUM(Amount) AS Total
FROM Boxes
WHERE EntryDate BETWEEN @.date1 AND @.date2 ANDArea=@.Area

the query cannot be ran unless the queries parameters were provided. I have to access this query in code to add the parameters from controls. Is it possible to access it or use sqlDataSource instead?

Thanks alot

Here is one example I grabed from tutorial with a little modifications for your reference:

Sub GetAuthors_Click(SenderAs Object, EAs EventArgs)

Dim DSAs DataSet
Dim MyConnectionAs SqlConnection
Dim MyCommandAs SqlDataAdapter

Dim strSelectCommandAsString = "select * from Authors where state = @.State"

MyConnection =New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("PubString").ConnectionString
MyCommand =New SqlDataAdapter(strSelectCommand, MyConnection)

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@.State", SqlDbType.NVarChar, 2))
MyCommand.SelectCommand.Parameters("@.State").Value = someValue 'you need send in

DS =new DataSet()
MyCommand.Fill(DS, "Authors")

Mygv.DataSource=DS.Tables("Authors").DefaultView
Mygv.DataBind()
End Sub

You can add all your parameters to your SqlDataAdapter from your code.

|||Thanks Limno

accessing parameters in a subreport

I have a report with an imbedded SubReport. I have set up the
subreport control to pass a parameter from the parent report to the
subreport. However, I'm stuck trying to actually use that parameter
within the subreport. This parameter will be used within a SQL
statement in the dataset tab.
I've tried setting a report parameter within the subreport and a
parameter within the dataset. I'm at a loss. Seems pretty simple, but
I'm obviously overlooking something. Any thoughts would be welcome.
ThanksSubreports are nothing special. They are a report that you have embedded.
You should design the report that will be used as a subreport first as a
report with report parameters. Test that report separately. Then after
embedding the report you do a right mouse click, parameters on the subreport
and map what the parameters should be.
Now, if you don't know how to use query parameters/report parameters that is
another matter and not really a subreport issue.
If you have a query that is like this:
select * from sometable where somefield = @.MyParam
Then RS automatically creates a report parameter called MyParam (note that
parameters are case sensitive).
When dealing with parameters you might be best to switch from graphical
designer mode to generic mode (the button is to the right of the ...).
Now, after embedding the report as a subreport you will map the MyParam
parameter to something in your main report. Either a field or a report
parameter.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
<dbutler_05@.hotmail.com> wrote in message
news:1166472829.204286.113100@.79g2000cws.googlegroups.com...
>I have a report with an imbedded SubReport. I have set up the
> subreport control to pass a parameter from the parent report to the
> subreport. However, I'm stuck trying to actually use that parameter
> within the subreport. This parameter will be used within a SQL
> statement in the dataset tab.
> I've tried setting a report parameter within the subreport and a
> parameter within the dataset. I'm at a loss. Seems pretty simple, but
> I'm obviously overlooking something. Any thoughts would be welcome.
> Thanks
>|||I figured it was something stupid simple. Just trying to make it hard
than it is.
Thanks for the help.
Bruce L-C [MVP] wrote:
> Subreports are nothing special. They are a report that you have embedded.
> You should design the report that will be used as a subreport first as a
> report with report parameters. Test that report separately. Then after
> embedding the report you do a right mouse click, parameters on the subreport
> and map what the parameters should be.
> Now, if you don't know how to use query parameters/report parameters that is
> another matter and not really a subreport issue.
> If you have a query that is like this:
> select * from sometable where somefield = @.MyParam
> Then RS automatically creates a report parameter called MyParam (note that
> parameters are case sensitive).
> When dealing with parameters you might be best to switch from graphical
> designer mode to generic mode (the button is to the right of the ...).
> Now, after embedding the report as a subreport you will map the MyParam
> parameter to something in your main report. Either a field or a report
> parameter.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> <dbutler_05@.hotmail.com> wrote in message
> news:1166472829.204286.113100@.79g2000cws.googlegroups.com...
> >I have a report with an imbedded SubReport. I have set up the
> > subreport control to pass a parameter from the parent report to the
> > subreport. However, I'm stuck trying to actually use that parameter
> > within the subreport. This parameter will be used within a SQL
> > statement in the dataset tab.
> >
> > I've tried setting a report parameter within the subreport and a
> > parameter within the dataset. I'm at a loss. Seems pretty simple, but
> > I'm obviously overlooking something. Any thoughts would be welcome.
> >
> > Thanks
> >