Showing posts with label line. Show all posts
Showing posts with label line. Show all posts

Wednesday, March 28, 2012

Passing Multivalue Parameters Through a Report Link

I've created a line chart in my report which lists number of transactions by month. I've also created a report to list transactions by day. My goal is for the user to select a month and link the report to the graph with the selected month divided up into days (in other words, the user wants to see the number of transactions for each day in the selected month).

Anyway, everything is working perfectly except for one thing. In the list of parameters that I am passing to the report for each day, I want to pass a multivalue parameter which contains all the transaction IDs the user selected in creating the report (these are supplied by a multivalue parameter). However, in the parameter dialog box where it asks for a value to send to the awaiting parameter, I do not know how to supply more than one value. If I need to pass one value, it will work fine. However, I would like to do something like:

JOIN(Parameters!TransactionID.value, ",")

for the value of TransactionID, but when I generate the report it is not accepting the values. I'm pretty sure its just a format issue, and I just need to know how exactly I should pass these values.

I already understand that when passing multivalue parameters in a URL you need something like:

TransactionID=1&TransactionID=2

...in order to select multiple values. However, this is a slightly different situation. I'm really running out of ideas, so any help would be much appreciated.

Thank you guys so much

can you please paste your select statement, multivalue parameters are automatically rendered if you have something like this in your select

select * from employees where managerid IN(select managerid from managers)

|||

Have you tried:

SELECT *

FROM Managers

WHERE ManagerID in (@.ManagerParm)

This works in Oracle (except for : instead of @.) and I would be surprised if it did not work in SQL server.

NOTE you will not be able to test it using the !, but it it will work for the report.

|||

I'm sorry I wasn't clear. The project I have is in RS 2005 and uses an analysis services data source and the select statement is entirely in MDX. However, the problem really isn't in the select statement. My problem is that I am creating a report link and I want to pass all the values selected in a multivalue parameter to the other report.

If you want to see reproduce the problem, try these steps:

Create a report with a multivalue parameter. Add a textbox. Right-click and select properties. Click the Navigation tab and select "Jump to Report". Select a valid report that accepts a multivalue parameter. Click the parameters button. In the parameter name column, select the multivalue parameter to receive the values. In the parameter value column, I need to pass the values for the current multivalue parameter. This is the problem I am having.

|||

Please read this related thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=163803&SiteID=1

It describes the various scenarios of passing multi value parameters to a drillthrough or subreport. In your case, it should be sufficient to just specify =Parameters!ParameterName.Value to pass all values along.

However, note that if the target report contains a parameterized MDX query and you want to use the passed-in parameter values directly in that query, the parameter values in the main report must represent the UniqueNames (not the caption which is usually the parameter label) - otherwise the target MDX query will most likely not work.

-- Robert

|||Thank you, it works perfectly!!sql

Wednesday, March 21, 2012

Passing Command line arguments from Visual Studio

Hi all,

Is it possible to pass command line arguments to a package when running it from within VS? I want to set the value of a variable via the commandline, and found that you can to this in DtExec with the "/set \Package.Variables[...].Value;..." syntax. According to the docs, you should be able to pass the same argument via the 'CmdLineArguments' property in the 'Properties' dialog of an SSIS project in VS (CmdLineArguments. Run the package with the specified command-line arguments. For information about command-line arguments, see dtexec Utility), but unfortunately, this doesn't seem to work (even though the exact same argument does work when entered in DtExec)

Any help would be greatly appreciated :-)

Steven

No. Since you are in a IDE/Debug environment with Visual Studio, I think it is a minor limitation that you cannot do this, you can just change and set anything your require in the IDE.

If you have external configuration information you wish to set all the time then /SET is probably not the best solution. Using the built in Configurations support in SSIS would be a better choice and this does work in VS. See the SSIS menu.

|||

I have the exact same issue. I just need a single parameter that needs to change every time I call my package, so it doesn't really warrant external configuration. The following article implies that CmdLineArguments are only taken into account whenever you use dtexec externally to execute the package and then attach to it to debug. See the last section ("Testing and Debugging your code") for details.

http://msdn2.microsoft.com/en-us/library/ms403356.aspx

Passing Command line arguments from Visual Studio

Hi all,

Is it possible to pass command line arguments to a package when running it from within VS? I want to set the value of a variable via the commandline, and found that you can to this in DtExec with the "/set \Package.Variables[...].Value;..." syntax. According to the docs, you should be able to pass the same argument via the 'CmdLineArguments' property in the 'Properties' dialog of an SSIS project in VS (CmdLineArguments. Run the package with the specified command-line arguments. For information about command-line arguments, see dtexec Utility), but unfortunately, this doesn't seem to work (even though the exact same argument does work when entered in DtExec)

Any help would be greatly appreciated :-)

Steven

No. Since you are in a IDE/Debug environment with Visual Studio, I think it is a minor limitation that you cannot do this, you can just change and set anything your require in the IDE.

If you have external configuration information you wish to set all the time then /SET is probably not the best solution. Using the built in Configurations support in SSIS would be a better choice and this does work in VS. See the SSIS menu.

|||

I have the exact same issue. I just need a single parameter that needs to change every time I call my package, so it doesn't really warrant external configuration. The following article implies that CmdLineArguments are only taken into account whenever you use dtexec externally to execute the package and then attach to it to debug. See the last section ("Testing and Debugging your code") for details.

http://msdn2.microsoft.com/en-us/library/ms403356.aspx

sql

Tuesday, March 20, 2012

Passing a variable into a stored procedure

Please take a look at line 18, how can I pass a variable into this instead of hard coding "Ann" in as the parameter.

I am wanting to do something along the following lines:
18. cmdLastName.Parameters.Add( "@.firstname", " & myvariable & " )

1. <%@. Import Namespace="system.Data.SqlClient" %>
2. <%@. Import Namespace="System.Data" %>
3. <%
4. Dim conPubs As SqlConnection
5. Dim cmdLastName as SqlCommand
6. Dim paramLastName As SqlParameter
7. Dim paramphone As SqlParameter
8. Dim strLastName As String
9. Dim phone as string

12. conPubs = New SqlConnection
13. ("server=localhost;uid=WebUserRX;pwd=ViglenWebUser;database=pubs")
14. cmdLastName = New SqlCommand("GetLastName", conPubs)
15. cmdLastName.CommandType = CommandType.StoredProcedure

17. 'FirstName Input Parameter
18. cmdLastName.Parameters.Add( "@.firstname", "Ann" )

'LastName Output Parameter
paramLastName = cmdLastName.Parameters.Add( "@.lastname", SqlDbType.Varchar )
paramphone = cmdLastName.Parameters.Add( "@.phone", SqlDbType.Varchar )

paramLastName.Size = 40
paramLastName.Direction = ParameterDirection.Output
paramphone.Size = 40
paramphone.Direction = ParameterDirection.Output

'Execute Command
conPubs.Open()
cmdLastName.ExecuteNonQuery()

'Retrieve value of Output Parameter
If Not IsDBNull( cmdLastName.Parameters( "@.lastname" ).value ) then
strLastName = cmdLastName.Parameters( "@.lastname" ).value
phone = cmdLastName.Parameters( "@.phone" ).value
else
strLastName = "Unknown"
End if
conPubs.Close
%>
The last name is <%=strLastName%><br>
Phone = <%=phone%
ThanXThere are several ways. I think the easiest to code would be like this (you'd need to use the correct datatype and length):

18. cmdLastName.Parameters.Add("@.firstname", SqlDbType.VarChar,99).Value=myvariable

Terri|||Thanks that works but do you know how I can return more than one record, do I need a loop around line 32? I have a dropdownlist which when autoposted sends a variable to a stored procedure, then only one row is returned. What I would like to do is when the dropdown is autoposted all the records (all rows) are returned and put into a datagrid.

When I use SQL within an aspx page I use a datareader and simply bind the result of the SQL to a web control e.g

myDropDownList2.DataSource = myDataReader
myDropDownList2.DataBind()

But via the Stored Procedure method I cannot see how this is achieved. Any code samples would be much appreciated.

1. <%
2. Dim conPubs As SqlConnection
3. Dim cmdLastName as SqlCommand
4. Dim paramLastName As SqlParameter
5. Dim strLastName As String
6. Dim mystr as string

8. mystr = myDropDownList2.SelectedItem.Value
9. Response.write("mystr= " & mystr & "<br>")

11. conPubs = New SqlConnection
12. ("server=marketstore;uid=steve;pwd=;database=Contents")
13. cmdLastName = New SqlCommand("GetLastNames", conPubs)
14. cmdLastName.CommandType = CommandType.StoredProcedure

17. 'FirstName Input Parameter
18. cmdLastName.Parameters.Add("@.firstname", SqlDbType.VarChar,99).Value = mystr

20. 'LastName Output Parameter
21. paramLastName = cmdLastName.Parameters.Add( "@.lastname", SqlDbType.Varchar )

24. paramLastName.Size = 40
25. paramLastName.Direction = ParameterDirection.Output

27. 'Execute Command
28. conPubs.Open()
29. cmdLastName.ExecuteNonQuery()

31. 'Retrieve value of Output Parameter
32. If Not IsDBNull( cmdLastName.Parameters( "@.lastname" ).value ) then
33. strLastName = cmdLastName.Parameters( "@.lastname" ).value
34. else
35. strLastName = "Unknown"
36. End if
37. conPubs.Close
%>|||Sure, you can take the resultset of a stored procedure, put them into a DataReader, and then bind the DataReader to the drop-down list. Replacing your lines 20-37:

20. Dim myReader As SqlClient.SqlDataReader
21. 'Execute Command
22. conPubs.Open()
23. myDataReader = cmdLastName.ExecuteReader()
24. myDropDownList2.DataSource = myDataReader
25. myDropDownList2.DataBind()
26. conPubs.Close

The SELECT statement in your stored procedure would be something like:

SELECT lastname FROM myTable WHERE firstname = @.firstname

where currently you probably have something like this:
SELECT @.lastname = lastname FROM myTable WHERE firstname = @.firstname

You would not use an Output parameter when you are returning more than one row. Instead you would return a set of records.

Terri|||Thanks I have that working now, but now I have a new issue, I am wanting to use a DataAdapter instead of a Datareader because i wish to add paging to my site, do you know the equivalent for 'Parameters' in DataAdapter terms as I wish to pass this variable into my stored proc and I am getting this error message, thanks in advance.

Compiler Error Message: BC30456: 'Parameters' is not a member of 'System.Data.SqlClient.SqlDataAdapter'.

Source Error:

Line 23: Dim paramvar As New SqlParameter
Line 24:
Line 25:
Line 26: paramvar = objDA.Parameters.Add("@.myvar", SqlDbType.VarChar,99).Value = "Steve"

Source File: C:\Inetpub\wwwroot\aspnet\datalistpaging2.aspx Line: 26|||You don't add parameters to a data adapter. You add them to the SQLCommand just as before.

Please review theTutorials section of this site, especially Server Side Data Access, and "Parameterized Selects" within that topic. You should be able to work out what you need for yourself from that.

Here's a stab at your code, but I did not test it.

1. <%
2. Dim conPubs As SqlConnection
3. Dim cmdLastName as SqlCommand
4. Dim paramLastName As SqlParameter
5. Dim strLastName As String
6. Dim mystr as string

8. mystr = myDropDownList2.SelectedItem.Value
9. Response.write("mystr= " & mystr & "<br>")

11. conPubs = New SqlConnection
12. ("server=marketstore;uid=steve;pwd=;database=Contents")
13. cmdLastName = New SqlCommand("GetLastNames", conPubs)
14. cmdLastName.CommandType = CommandType.StoredProcedure

17. 'FirstName Input Parameter
18. cmdLastName.Parameters.Add("@.firstname", SqlDbType.VarChar,99).Value = mystr

20. Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(cmdLastName)
21. Dim myDataSet As DataSet = New DataSet()
22. myDataAdapter.Fill(myDataSet,"LastNames")
23. myDropDownList2.DataSource = myDataSet.Tables("LastName").DefaultView
24. myDropDownList2.DataBind()
25. conPubs.Close

Terri

Passing a selected row column value to the stored procedure

I have a simple Gridview control that has a delete command link on it.

If I use the delete SQL code in line it works fine. If I use a stored procedure to perform the SQL work, I can't determine how to pass the identity value to the SP. Snippets are below...

The grid
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="member_id" HeaderText="member_id" InsertVisible="False"
ReadOnly="True" SortExpression="member_id" />
<asp:BoundField DataField="member_username" HeaderText="member_username" SortExpression="member_username" />
<asp:BoundField DataField="member_firstname" HeaderText="member_firstname" SortExpression="member_firstname" />
<asp:BoundField DataField="member_lastname" HeaderText="member_lastname" SortExpression="member_lastname" />
<asp:BoundField DataField="member_state" HeaderText="State" SortExpression="member_state" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:rentalConnectionString1 %>"
SelectCommand="renMemberSelect" SelectCommandType="StoredProcedure"
DeleteCommand="renMemberDelete" DeleteCommandType="StoredProcedure"
OldValuesParameterFormatString="original_{0}"
>

<DeleteParameters>

<asp:Parameter Name="member_id" Type="Int32" />

</DeleteParameters>

</asp:SqlDataSource
the SP

CREATE PROCEDURE renMemberDelete
@.member_id as int
As UPDATE [renMembers]
SET member_status=1
WHERE [member_id] = @.member_id
GO

Try:GridView2.DataKeyNames="member_id"

or

<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource2" DataKeyNames="member_id">