New Message on dotNET User Group Hyd

rverhelp required on input/output parameters in sql

Reply
  Reply to Sender   Recommend Message 2 in Discussion
From: Vishnu-Chivukula

Hi Kishore,
 
Assume that your SP, named "StoredProcedureName", takes a single input parameter and returns an output.
 
CREATE PROCEDURE StoredProcedureName
@ProductCode [nvarchar](20),
@Control [nvarchar](20) OUTPUT
WITH EXECUTE AS CALLER
AS
BEGIN
select @Control = columnname from traceparameters where keyLabel = 'Test'
return @Control
END
 
In your code create a SqlParameter object as Sqlparameter parameter;
Creare a connection string and open the connection...
Create a command object and assign the connection object to it..
In case you have a stored procedure set the commandtype property of command object to storedprocedure. The name of the stored procedure
will assigned to the commandtext property
So u r code will look like this..
 
           SqlCommand command;
           SqlParameter parameter;
           string columnName = null;
           try
           {
               using (SqlConnection dbConnection = Connection())
               {
                   command = new SqlCommand();
                   command.Connection = dbConnection;
                   command.CommandType = CommandType.StoredProcedure;
                   command.CommandText = "StoredProcedureName";
                   parameter = new SqlParameter("@ProductCode", SqlDbType.NVarChar, 20);
                   parameter.Value = ProductCode;
                   command.Parameters.Add(parameter);
                   parameter = new SqlParameter("@Control", SqlDbType.NVarChar, 20);
                   parameter.Direction = ParameterDirection.Output;
                   command.Parameters.Add(parameter);
                   command.ExecuteNonQuery();
                   columnName = command.Parameters["@Control"].Value.ToString();
                   return columnName;
               }
           }
           catch (Exception ex)
           {
               throw new Exception("Stored Procedure Failed" + ex.ToString());
           }
 
This is for a SQL backend...  Use the same logic for other database...
Hope i got u r question right....
 
Need any help, do post a msg back..
 
 
Happy Coding..

View other groups in this category.


Also on MSN:
Start Chatting | Listen to Music | House & Home | Try Online Dating | Daily Horoscopes

To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.

Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.

If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.

Reply via email to