简体   繁体   中英

Stored Procedure DAL

How to create a common DAL layer method for stored procedure which has output parameters.

When stored procedure has output parameters, you will not be able to retrieve the results in dataset or data reader as collection. Please tell me which is the best way to have a common method to accept any input and output parameters and return values from output parameters.

This Link : http://www.4guysfromrolla.com/articles/070203-1.aspx Contains all the Information From where to download the SqlHelper and how to use and implement in your project..

Which might help you

Something like that:

public static void DalWrapper(int id, string str, out int resultid, out string resultstring)
{
  * call the SP passing id and str
  * assign resulting values to resultid and resultstring
}

Depending on needs out can be changed to ref

You can use ExecuteNonQuery and the get the value of the parameter

using (SqlConnection conn = new SqlConnection())    
{
    SqlCommand cmd = new SqlCommand("sp", conn);   cmd.CommandType = CommandType.StoredProcedure;

    cmd.Parameters.Add(new SqlParameter("@param", SqlDbType.Int, int.MaxValue, ParameterDirection.Output));

    conn.Open();
    cmd.ExecuteNonQuery();
    int id = cmd.Parameters["@param"].Value;

    conn.Close();    
 }

Almost the same post with this one. See this: Get output parameter value in ADO.NET

This will surely help you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM