Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I have the store procedure as described below with four input fields and few output fields. I want to call this procedure from the method : dueDate(Request reqObj) { ... }
I want to log the data that is there in reqObj. the input filed described in stored procedure are defined in the Request class. How would be the syntax of the piece of code to call this stored procedure and log the input as well as output fields.


PROCEDURE vrP_GetOrderDetailsByMON
(
i_MASTERORDERNUM IN SERVICEORDER.MASTERORDERNUM%TYPE,
i_SERVICEORDERNUM IN SERVICEORDER.SERVICEORDERNUM%TYPE,
i_SERVICEORDERTYPE IN SERVICEORDER.SERVICEORDERTYPE%TYPE,
i_STATECODE IN SERVICEORDER.STATECODE%TYPE,

o_WIRECENTERID OUT SERVICEORDER.WIRECENTERID%TYPE,
o_CLASSOFSERVICENAME OUT SERVICEORDER.CLASSOFSERVICENAME%TYPE,
o_HSIIND OUT SERVICEORDERRESERVATION.UNITYIND%TYPE,
o_MCN OUT SERVICEORDER.MCN%TYPE,
o_SERVICECODEMODIFIER OUT SERVICEORDER.SERVICECODEMODIFIER%TYPE,
o_SERVICEADDRESS OUT SERVICEORDER.SERVICEADDRESS%TYPE,
o_EASTORDERDETAILSFLAG OUT CHAR,
o_WESTORDERDETAILSFLAG OUT CHAR,
--FTTPDETAILS--------
o_FTTPONTREQUIREDIND OUT SERVICEORDER.FTTPONTREQUIREDIND%TYPE,
o_FTTPENGINEERINGINTERVAL OUT SERVICEORDER.FTTPENGINEERINGINTERVAL%TYPE,
o_FTTPDROPTYPE OUT SERVICEORDER.FTTPDROPTYPE%TYPE,
o_FTTPONTTYPE OUT SERVICEORDER.FTTPONTTYPE%TYPE,
Posted

1 solution

Well nice question.... You need to use SqlParameter[] for executing this type of storedprocedure. The question is how this could be done... See the following code snippets..

(i) Input / Calling the StoredProcedure:
C#
for (iCount = 0; iCount <= 4; iCount++)
{
    oSQLParameter[iCount] = new SqlParameter();
    if (iCount == 4)
    // set the output parameter  
        oSQLParameter[iCount].Direction = ParameterDirection.Output;
    else 
    oSQLParameter[iCount].Direction = ParameterDirection.Input;
}
oSQLParameter[0].ParameterName = MyParama;
oSQLParameter[0].Size = 30;
oSQLParameter[0].Value = "Test";
..........
..........

//Call the ExecuteNonQueryStoredProcedure with the required parameters..
//Get the retValur
retValur= oSQLParameter[4].Value.ToString();


(ii) Executing the StoredProcedure:
C#
public int ExecuteNonQueryStoredProcedure(string strConnectionString, string strStoredProcedureName, SqlParameter[] _ObjSqlParameter)
        {
            //   declare variables
            SqlConnection _ObjConnection;
            SqlCommand _ObjCommand;
            int iRowsAffected;
            //   prepare a connection
            _ObjConnection = new SqlConnection(strConnectionString);
            //   open connection
            _ObjConnection.Open();
            //   prepare command
            _ObjCommand = new SqlCommand(strStoredProcedureName, _ObjConnection);
            _ObjCommand.CommandType = CommandType.StoredProcedure;

            //   asign parameters to command
            //SqlParameter collObj ;
            foreach (SqlParameter collObj in _ObjSqlParameter)
            {
                _ObjCommand.Parameters.Add(collObj);
            }

            // execute command
            iRowsAffected = _ObjCommand.ExecuteNonQuery();

            _ObjCommand.Dispose();
            _ObjConnection.Close();
            _ObjConnection.Dispose();

            //   return affected rows
            return iRowsAffected;
        }


Hope this may helped you... :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900