Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Friday, March 30, 2012

How to simulate an array in SQL Server

Just thought some might be interested in how to identify individual
items in an 'array' by declaring a local variable as table
----
declare @.MyTable table (MyRowID int identity, MyData varchar(255))
declare @.MyCurrentRow as int
declare @.MyRowCount as int
insert into @.MyTable select Name from sysobjects -- (or whatever)
set @.MyRowCount = @.@.RowCount
-- @.@.Rowcount hold the count of the last table in these cases anyway
-- then you can use statement to access the nth. row in the 'array'
select MyData from @.MyTable where MyRowID = 5 -- as an example
--
-- or step through the table using @.MyCurrentRow
Set @.MyCurrentRow = 1
while @.MyCurrentRow < @.MyRowCount +1
Begin
Select MyData from @.MyTable where MyRowID = @.MyCurrentRow
set @.MyCurrentRow = @.MyCurrentRow + 1
Continue
end
Just thought it might help. It isn't rocket science but I saw a few
with problems so thought I'd post.
I needed it to obtain individual values from a table and use those
values to call a stored procedure repeatedly.
CheersSee if these help:
http://www.aspfaq.com/show.asp?id=2248 Arrays & Lists
http://www.sommarskog.se/dynamic_sql.html Dynamic SQL
http://www.users.drew.edu/skass/sql...bleProc.sql.txt List to
Table script
Andrew J. Kelly SQL MVP
<mal_k100@.hotmail.com> wrote in message
news:1125573743.271138.167070@.o13g2000cwo.googlegroups.com...
> Just thought some might be interested in how to identify individual
> items in an 'array' by declaring a local variable as table
> ----
> declare @.MyTable table (MyRowID int identity, MyData varchar(255))
> declare @.MyCurrentRow as int
> declare @.MyRowCount as int
> insert into @.MyTable select Name from sysobjects -- (or whatever)
> set @.MyRowCount = @.@.RowCount
> -- @.@.Rowcount hold the count of the last table in these cases anyway
> -- then you can use statement to access the nth. row in the 'array'
> select MyData from @.MyTable where MyRowID = 5 -- as an example
> --
> -- or step through the table using @.MyCurrentRow
> Set @.MyCurrentRow = 1
> while @.MyCurrentRow < @.MyRowCount +1
> Begin
> Select MyData from @.MyTable where MyRowID = @.MyCurrentRow
> set @.MyCurrentRow = @.MyCurrentRow + 1
> Continue
> end
> Just thought it might help. It isn't rocket science but I saw a few
> with problems so thought I'd post.
> I needed it to obtain individual values from a table and use those
> values to call a stored procedure repeatedly.
> Cheers
>sql

Sunday, February 19, 2012

How to send parameters to report when executing ReportingService.Render

I'm trying to figure out how you send/set the report variables when using the ReportingService.Render method.

I can get the ReportParameters array using GetReportParameters but can't seem to find a way to populate the ParameterValue array that is passed as a variable in the Render method. I've tried creating an ArrayList comprised of ParameterValue objects (non-array), adding them to the ArrayList, and trying to convert that to a ParameterValue array. The example code I found is in VB.NET and looks like this:

reportParametersArray = rs.GetReportParameters(reportPath, Nothing, True, _
reportParameterValuesArrayList.ToArray(GetType(ParameterValue)), Nothing)

I tried to do the same thing in C#:

rpReportParams = rsReports.GetReportParameters(sReportPath, null, true, arrayListParams.ToArray(System.Type.GetType(ParameterValue)), dscCredentials);

The compile error is :
'ReportService.ParameterValue' denotes a 'class' where a 'variable' was expected

Putting quotes around ParameterValue returns the following error:
Argument '4': cannot convert from 'System.Array' to 'ParameterValue[]'
Anyone had success populating report parameters or have a suggestion?

Thanks,

O.

If arrayListParams is an ArrayList that contains ParameterValue objects, try this in C#

(ParameterValue[])arrayListParams.ToArray(typeof(ParameterValue))