1

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.

Drew
  • 29,895
  • 7
  • 74
  • 104
Yavar
  • 11,883
  • 5
  • 32
  • 63

3 Answers3

1

This Link : https://web.archive.org/web/20211020111631/https://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

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
1

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

Oleg Dok
  • 21,109
  • 4
  • 45
  • 54
1

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();    
 }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ivo
  • 3,406
  • 4
  • 33
  • 56