Showing posts with label returned. Show all posts
Showing posts with label returned. Show all posts

Wednesday, March 28, 2012

How to get the returned value from a stored procedure?

Hi,

I use a strong-typed DataSet to build the data access tier of my application, and the IDE generates most of code for me. However I can't find a way to get the value returned by a stored procedure(The stored procedure seems like 'RETURN 0').I noticed that a @.RETURN_VALUE parameter is added automatically for each query method, but I don't know how to read the value.

Anybody could help me with the problem? Thanks.Big Smile

Hi,

I am assuming you are trying to return the value via VB or C#. You must load your sql command in to a data reader. It loads your values in an an array which is index. Here is an example which returns numerous values and assigns one of the values to a label.

VB:

Dim myConnectionAs SqlConnection
Dim myCommandAs SqlCommand
myConnection =New SqlConnection("Data Source=MYCOMPUTER\SQLEXPRESS;Initial Catalog=MYDATABASEIntegrated Security=True")
myConnection.Open()
' sql statment
myCommand =New SqlCommand("Exec MY_SP", myConnection)
Dim dr = myCommand.ExecuteReader()
Dim iAs Integer = 1

While dr.read()

 Me.lblmel.Text = dr(2).ToString

End While
dr.Close()
myConnection.Close()

C#:

 SqlConnection myConnection;
SqlCommand myCommand;
myConnection =new SqlConnection("Data Source=MYCOMPUTER\\SQLEXPRESS;Initial Catalog=MYDATABASEIntegrated Security=True");
myConnection.Open();
// sql statment
myCommand =new SqlCommand("Exec MY_SP", myConnection);
object dr = myCommand.ExecuteReader();

while (dr.read()) {

this.lblmel.Text = dr(2).ToString;

}
dr.Close();
myConnection.Close();

|||

U can use outparameter to get the value

Thank u

Baba

Please remember to click "Mark as Answer" on this post if it helped you.

Monday, March 26, 2012

How to get the percentage presentation of a returned value in MDX?

Hi, All,

How can we get the percentage presentation of a value (e.g. a/b, I want to get the result presented in percentage format). How can we achieve this in MDX?

Thanks a lot and I am looking forward to hearing from you shortly.

With best regardsd,

Yours sincerely,

Hi, experts,

Please help me out!

Thanks.

With kind regards,

Yours sincerely,

|||

Hi Helen

You need to create a calculated measure and then use Format_STRING:

Code Snippet

WITH

MEMBER [Measures].[yourMeasure] as

([Measures].[A] / [Measures].[B]),

Format_string="0.000%"

SELECT

[Measures].[yourMeasure]

ON COLUMNS

FROM

[Your Cube]

Hope this helps

Tim

|||

Hi, Tim,

Thanks a lot for your suggestion.

It works perfect.

With kindest regards,

Yours sincerely,

How to get the percentage presentation of a returned value in MDX expression for my KPI Definiti

Hi, All,

How can we get the percentage presentation of a value (e.g. a/b, I want to get the result presented in percentage format). How can we achieve this in MDX?

Thanks a lot and I am looking forward to hearing from you shortly.

With best regardsd,

Yours sincerely,

Hi, experts,

Please help me out!

Thanks.

With kind regards,

Yours sincerely,

|||

Hi Helen

You need to create a calculated measure and then use Format_STRING:

Code Snippet

WITH

MEMBER [Measures].[yourMeasure] as

([Measures].[A] / [Measures].[B]),

Format_string="0.000%"

SELECT

[Measures].[yourMeasure]

ON COLUMNS

FROM

[Your Cube]

Hope this helps

Tim

|||

Hi, Tim,

Thanks a lot for your suggestion.

It works perfect.

With kindest regards,

Yours sincerely,

Monday, March 19, 2012

How to get source by execution oracle sp using ref cursor

Hi,

I need to get recordset returned by oracle sp in execute sql task to process futher in For Each Loop container and on same lines i want to use oracle sp for extraction data in Data Flow Task. Could anybody suggest if it how we could do it in SSIS?

All suggestions will be highly appreciated.

Thanks,

Lalit

You should be able to do this. Is there a specific problem you are encountering?|||There is no variable type in SSIS that maps to refcursor type in Oracle. I don't think a variable of type object can be used for this either. So I guess you cannot execute Oracle SP using Execute SQL task to get the recordset.

Monday, March 12, 2012

How to get row count ?

To all gurus,
I am developing an application in which i want to show the number
of rows returned by the query.
e.g.
Select Categories.CategoryName, Products.ProductName,
Sum(([Order Details].UnitPrice*[Quantity]*(1-[Discount])/100)*100) AS
ProductSales
FROM
((([Order Details] INNER JOIN Orders ON [Order Details].OrderID =
Orders.OrderID)
INNER JOIN Products ON [Order Details].ProductID = Products.ProductID)
INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID)
WHERE
(Orders.ShippedDate) BETWEEN '1/1/1997' AND '12/31/1997'
GROUP BY
Categories.CategoryName, Products.ProductName

I want the number of rows returned by this query.
How can i get the number of rows?

Please help me..
waiting for your replies..

Prem
(premratan@.hotmail.com)Select count (*) as "row count" from (select <any query here>) as t

For some reason, the final table alias "as t" is required.

Goetz Graefe

"Prem" <premratan@.hotmail.com> wrote in message
news:2f7d06ff.0311111515.2a2a040c@.posting.google.c om...
> To all gurus,
> I am developing an application in which i want to show the number
> of rows returned by the query.
> e.g.
> Select Categories.CategoryName, Products.ProductName,
> Sum(([Order Details].UnitPrice*[Quantity]*(1-[Discount])/100)*100) AS
> ProductSales
> FROM
> ((([Order Details] INNER JOIN Orders ON [Order Details].OrderID =
> Orders.OrderID)
> INNER JOIN Products ON [Order Details].ProductID = Products.ProductID)
> INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID)
> WHERE
> (Orders.ShippedDate) BETWEEN '1/1/1997' AND '12/31/1997'
> GROUP BY
> Categories.CategoryName, Products.ProductName
> I want the number of rows returned by this query.
> How can i get the number of rows?
> Please help me..
> waiting for your replies..
> Prem
> (premratan@.hotmail.com)|||Refer to @.@.ROWCOUNT in SQL Server Books Online. If you are using ADO in your
application, then you can use the recordset's RecordCount property to get
the value at the client side.

--
-- Anith
( Please reply to newsgroups only )|||premratan@.hotmail.com (Prem) wrote in message news:<2f7d06ff.0311111515.2a2a040c@.posting.google.com>...
> To all gurus,
> I am developing an application in which i want to show the number
> of rows returned by the query.
> e.g.
> Select Categories.CategoryName, Products.ProductName,
> Sum(([Order Details].UnitPrice*[Quantity]*(1-[Discount])/100)*100) AS
> ProductSales
> FROM
> ((([Order Details] INNER JOIN Orders ON [Order Details].OrderID =
> Orders.OrderID)
> INNER JOIN Products ON [Order Details].ProductID = Products.ProductID)
> INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID)
> WHERE
> (Orders.ShippedDate) BETWEEN '1/1/1997' AND '12/31/1997'
> GROUP BY
> Categories.CategoryName, Products.ProductName
> I want the number of rows returned by this query.
> How can i get the number of rows?
> Please help me..
> waiting for your replies..
> Prem
> (premratan@.hotmail.com)

After running the query, you can do this:

select @.@.rowcount

If you need to use the value later, you can put it in a variable:

set @.rows = @.@.rowcount

Simon

Wednesday, March 7, 2012

How to get number of records returned by a data set?

Hi,
I am looking for a way to determine a number of records returned by my
dataset. The ultimate goal is to hide a table and dispaly informative
message, in case there are no records returned. This should be fairly
simple, but I can't seem to figure out how to get it. Thank you in advance!
MichaelYou can get it using the Count function. The sintaxis is:
=Count(Fields!some_field.Value, "Your_dataset")
You can use this to display the number of rows of a data set in a textbox.
You can also use it as a condition inside an IFF clause:
=IIF(Count(Fields!some_field.Value, "Your_dataset") = 0, action1, action2)
I hope this helps|||Works like a charm! Thank you very much!
- Michael

How to get number of records a query has returned using SqlDataSource control?

Hi,

I'm using SqlDataSource control.

Is there a way to know how many records a query has returned?

Try this one to get the total Rows Returned

This is a simple trick about how you can get the total of rows returned from your SqlDataSource control's SelectCommand query.

When you bind a data-source control to a GridView control and use paging etc, you can't use the GridView's Rows property to get the number of rows returned from your data-source control. The Rows property will only return the rows rendered by the GridView control. To get the total number of rows returned from the SelectCommand, you can hook up to the SqlDataSource's Selected event. The Selected event's SqlDataSourceStatusEventArgs event argument's AffectedRows property will return the number of totals rows the SelectCommand returnes. The following example is a simple page with a GridView, SqlDataSource control and a label control. The lable control will be used to display the total number of rows the SelectComamand of the SqlDataSource control returns.

<%@. Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="Server">

protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)

{

totalRows.Text = e.AffectedRows.ToString();

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"

DataSourceID="SqlDataSource1" AllowPaging="True">

<Columns>

<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />

<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />

<asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=(local);Initial Catalog=Northwind;Integrated Security=True"

ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName] FROM [Customers]" OnSelected="SqlDataSource1_Selected">

</asp:SqlDataSource>

<asp:Label ID="Label1" runat="server" Text="Number of total rows:"></asp:Label>

<asp:Label ID="totalRows" runat="server" Text="Label"></asp:Label>

</div>

</form>

</body>

</html>

Hope this will help you

Satya