Click here to Skip to main content
15,902,938 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: selecting a row in datagrid and swapping Pin
ptvce10-Oct-06 19:22
ptvce10-Oct-06 19:22 
GeneralRe: selecting a row in datagrid and swapping Pin
ptvce10-Oct-06 19:25
ptvce10-Oct-06 19:25 
GeneralRe: selecting a row in datagrid and swapping Pin
Krishlibran10-Oct-06 19:45
Krishlibran10-Oct-06 19:45 
QuestionMay i get the product key Num of VS 2005 Pin
ravikiranreddydharmannagari9-Oct-06 20:27
ravikiranreddydharmannagari9-Oct-06 20:27 
AnswerRe: May i get the product key Num of VS 2005 Pin
RichardGrimmer10-Oct-06 5:29
RichardGrimmer10-Oct-06 5:29 
Questionpopup window unable to write value in the parent window. Pin
ram19749-Oct-06 19:53
ram19749-Oct-06 19:53 
QuestionRetrival of stored data from a table using asp.net 2.0 Pin
brardavi9-Oct-06 19:51
brardavi9-Oct-06 19:51 
AnswerRe: Retrival of stored data from a table using asp.net 2.0 Pin
Sathesh Sakthivel9-Oct-06 20:07
Sathesh Sakthivel9-Oct-06 20:07 
The code sample above retrieves an entire record from a database table. Sometimes however we need only specific fields from a row in a database table. In this case we need to supply the stored procedure with not only an input parameter as in the previous section, but also one or more output parameters to store the result of the stored procedure.

The following is an example of a stored procedure which will take as input the CustomerID value and return only two fields: CompanyName and ContactName. For this limited result set, we have to use the AddOutputParameter() method. This method is used to return the output of a stored procedure.

It is recommended when executing a stored procedure with output parameters to use the ExecuteNonQuery() method instead of the ExecuteDataReader() method.

The SQL stored procedure is as follows:

CREATE PROCEDURE [dbo].[GetCustomerMultipleFields]<br />
(<br />
   @CustomerID NCHAR(5),<br />
   @CompanyName NVARCHAR(40) OUTPUT,<br />
   @ContactName NVARCHAR(30) OUTPUT<br />
) <br />
AS<br />
SET NOCOUNT ON<br />
   SELECT<br />
      @CompanyName = [CompanyName],<br />
      @ContactName = [ContactName]<br />
   FROM<br />
      [Customers]<br />
   WHERE<br />
      [CustomerID] LIKE @CustomerID<br />
GO<br />


The following C# code executes the above stored procedure and uses the AddOutputParameter() method to obtain the results:

<br />
try<br />
{<br />
   // Create DataBase Instance<br />
   Database db = DatabaseFactory.CreateDatabase();<br />
   // Initialize the Stored Procedure<br />
   DBCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper("GetCustomerMultipleFields");<br />
   dbCommandWrapper.AddInParameter("@CustomerID", DbType.String, "ALFKI");<br />
   dbCommandWrapper.AddOutParameter("@CompanyName", DbType.String, 40);<br />
   dbCommandWrapper.AddOutParameter("@ContactName", DbType.String, 30);<br />
   //Execute the stored procedure<br />
   db.ExecuteNonQuery(dbCommandWrapper);<br />
   //Display results of the query<br />
   string results = string.Format("Company Name : {0}, Contact Name {1},",<br />
        dbCommandWrapper.GetParameterValue("@CompanyName"),<br />
        dbCommandWrapper.GetParameterValue("@ContactName"));<br />
   Response.Write(results);<br />
}<br />
catch (Exception ex)<br />
{<br />
   Response.Write(ex.ToString());<br />
}<br />


In the above code, I passed a customer ID value to the stored procedure as an input parameter. As the stored procedure is designed to return two values, CompanyName and ContactName, these were identified as output parameters.

To display the returned values we used another method of dbCommandWrapper, which is GetParameterValue(“ParameterName”). This method returns the value of the parameter specified.



With Regards

Satips

AnswerRe: Retrival of stored data from a table using asp.net 2.0 Pin
brardavi9-Oct-06 20:28
brardavi9-Oct-06 20:28 
GeneralRe: Retrival of stored data from a table using asp.net 2.0 Pin
Sathesh Sakthivel9-Oct-06 20:45
Sathesh Sakthivel9-Oct-06 20:45 
GeneralRe: Retrival of stored data from a table using asp.net 2.0 Pin
Jay_se9-Oct-06 21:42
Jay_se9-Oct-06 21:42 
QuestionServer.Transfer vs Response.Redirect Pin
psamy9-Oct-06 18:59
psamy9-Oct-06 18:59 
AnswerRe: Server.Transfer vs Response.Redirect Pin
Sathesh Sakthivel9-Oct-06 19:11
Sathesh Sakthivel9-Oct-06 19:11 
AnswerRe: Server.Transfer vs Response.Redirect Pin
Jay_se9-Oct-06 19:13
Jay_se9-Oct-06 19:13 
QuestionApplication.DoEvents in ASP.Net? Pin
Mei Yoong9-Oct-06 18:37
Mei Yoong9-Oct-06 18:37 
AnswerRe: Application.DoEvents in ASP.Net? Pin
safat9-Oct-06 20:12
safat9-Oct-06 20:12 
AnswerRe: Application.DoEvents in ASP.Net? Pin
Mei Yoong9-Oct-06 21:15
Mei Yoong9-Oct-06 21:15 
GeneralRe: Application.DoEvents in ASP.Net? Pin
safat10-Oct-06 1:48
safat10-Oct-06 1:48 
GeneralRe: Application.DoEvents in ASP.Net? Pin
Mei Yoong17-Oct-06 16:41
Mei Yoong17-Oct-06 16:41 
QuestionDelete File from Server??? Pin
code-frog9-Oct-06 16:34
professionalcode-frog9-Oct-06 16:34 
AnswerRe: Delete File from Server??? Pin
Steve Echols9-Oct-06 19:34
Steve Echols9-Oct-06 19:34 
AnswerRe: Delete File from Server??? Pin
Sam_IN9-Oct-06 21:59
Sam_IN9-Oct-06 21:59 
QuestionMoving a masterpage contentplaceholder around Pin
ThePlagueIsBack9-Oct-06 13:14
ThePlagueIsBack9-Oct-06 13:14 
AnswerRe: Moving a masterpage contentplaceholder around Pin
Mike Ellison9-Oct-06 14:12
Mike Ellison9-Oct-06 14:12 
GeneralRe: Moving a masterpage contentplaceholder around Pin
ThePlagueIsBack9-Oct-06 14:15
ThePlagueIsBack9-Oct-06 14:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.