472,354 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

Getting an Output Parameter from a SqlDataSource


This is a my solution to getting an Output parameter from a SqlDataSource.

I have seen a few scant articles but none of them take it all the way to
a solution. Hopefully this will help some poor soul.

Situation: I want to do a lookup using a stored procedure for each
value in a Row within a GridView.

I use a lookup function in my code behind, evaluating the necessary
bound fields. The problem is the SqlDataSource representing the stored
procedure was returning an empty string after running the .Select() method.

<asp:Label
ID="FieldValue"
runat="server" Text='<%#
lookupValueName((string)DataBinder.Eval(Container, "DataItem.FieldName"),(string)DataBinder.Eval(Cont ainer,"DataItem.FieldValue"))
%>'>
</asp:Label>
However, after some research, I found that I did see the Output
parameter in the Selecting event, but only in the
SqlDataSourceStatusEventArgs object. Finally, it occured to me, I
would simply set the Output parameter for the SqlDataSource in the
Selecting event handler.

protected void SQLDataSource5_Selected(
object sender,
SqlDataSourceStatusEventArgs e)
{
SqlDataSource5.SelectParameters["ValueName"].DefaultValue =
e.Command.Parameters["@ValueName"].Value.ToString();
}

I guess it was built this way to allow the developer to handle datatype
conversions in the Selected event handler and parameter setup in the
Selecting event handler.

Then when I was back in my lookup function, I could access the value of
the output paramter.

string valuename =
SqlDataSource5.SelectParameters["ValueName"].DefaultValue;

An alterative may have been to add the data source to the GridRow
ItemTemplate...however, since I was using an asp:label, I didn't see a
method to bind the output parameter to the label.
Mar 30 '07 #1
1 12134
I'm not sure this will help you. You have a lot of words, and it's late
where I live. Here's an example of how to use output parameters to get data
from SQLServer. This runs against Northwind.
How to get a parameter back:

Dim SQLString = "SELECT @UnitPrice = UnitPrice, " & _
" @UnitsInStock = UnitsInStock, " & _
"FROM Products WHERE ProductName = @ProductName"

Dim pUnitPrice, pInStock, pProductName As SqlParameter
pUnitPrice = cmd.Parameters.Add("@UnitPrice", SqlDbType.Money)
pUnitPrice.Direction = ParameterDirection.Output
pInStock = cmd.Parameters.Add("@UnitsInStock", SqlDbType.NVarChar, 20)
pInStock.Direction = ParameterDirection.Output
pProductName = cmd.Parameters.Add("ProductName", SqlDbType.NvarChar, 40)
pProductName.Value = "Chai"

cmd.ExecuteNonQuery()
if pUnitPrice.Value Is DBNull.Value Then 'none were found
Console.WriteLine("No product found named {0}", pProductName.Value)
Else
Console.WriteLine("Unit price: {0}", pUnitPrice.Value)
Console.WriteLine("In Stock: {0}", pInStock.Value)
End If

Robin S.
--------------------------------
"John Bailo" <ja*****@texeme.comwrote in message
news:Uo******************************@speakeasy.ne t...
>
This is a my solution to getting an Output parameter from a
SqlDataSource.

I have seen a few scant articles but none of them take it all the way to
a solution. Hopefully this will help some poor soul.

Situation: I want to do a lookup using a stored procedure for each value
in a Row within a GridView.

I use a lookup function in my code behind, evaluating the necessary bound
fields. The problem is the SqlDataSource representing the stored
procedure was returning an empty string after running the .Select()
method.

<asp:Label
ID="FieldValue"
runat="server" Text='<%#
lookupValueName((string)DataBinder.Eval(Container, "DataItem.FieldName"),(string)DataBinder.Eval(Cont ainer,"DataItem.FieldValue"))
%>'>
</asp:Label>
However, after some research, I found that I did see the Output parameter
in the Selecting event, but only in the SqlDataSourceStatusEventArgs
object. Finally, it occured to me, I would simply set the Output
parameter for the SqlDataSource in the Selecting event handler.

protected void SQLDataSource5_Selected(
object sender,
SqlDataSourceStatusEventArgs e)
{
SqlDataSource5.SelectParameters["ValueName"].DefaultValue =
e.Command.Parameters["@ValueName"].Value.ToString();
}

I guess it was built this way to allow the developer to handle datatype
conversions in the Selected event handler and parameter setup in the
Selecting event handler.

Then when I was back in my lookup function, I could access the value of
the output paramter.

string valuename =
SqlDataSource5.SelectParameters["ValueName"].DefaultValue;

An alterative may have been to add the data source to the GridRow
ItemTemplate...however, since I was using an asp:label, I didn't see a
method to bind the output parameter to the label.

Apr 1 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sandie Towers | last post by:
We use a number of similar databases and frequently create a new database using a backup restore of another similar database. We try to keep changes between databases in _Additional tables - like...
5
by: vivienne.netherwood | last post by:
I am developing an Access Project front end with a SQL server database. I have written a stored procedure that returns a record set and also a value via an output parameter. The procedure is as...
8
by: Patreek | last post by:
Hi, On the line where I'm assigning RecordCount to be the value of my output parameter, I'm getting the generic "Object reference not set to an instance of an object" error. I've isolated it...
4
by: Mr Not So Know It All | last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE . @in_rc varchar(8) @out_eList...
0
by: rockdale | last post by:
Hi, All How to get the output parameter's value when you use the SQLHelper (Microsoft Data Access Block)? When I try to access my ourput parm I got the following error. ...
8
by: Alec MacLean | last post by:
Hi, I'm using the DAAB Ent Lib (Jan 2006) for .NET 2.0, with VS 2005 Pro. My project is a Web app project (using the WAP add in). Background: I'm creating a survey system for our company, for...
7
by: ashtek | last post by:
Hi, I have a generic function that executes a stored procedure & returns a data table. Code: === public static DataTable ExecuteStoredProcedure(string strProc,SqlParameter paramArray) {...
1
by: Mike Lester | last post by:
I have a need for a stored procedure to return a recordset AND an output parameter that contains the count of records in the recordset. I can get either but not both. (ie. if there is a select...
8
by: Mike P | last post by:
How do you return a datareader from a stored procedure, but also return an output parameter? Here is my code, which is just returning a data reader at the moment : _conn.Open(); SqlCommand...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.