You must Sign In to post a response.
  • Category: ASP.NET

    How to retrieve value of output parameter in c#

    Hello ,
    I am creating a 3 tier application where after i have registration form and login form.After registration of a user i need to give him/her a userid and a random password.I have made a stored proc which generates random password now i need to display it in after registration as well as userid.How could i achieve this?

    Hoping to get help from my friends!!
  • #762654

    using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
    using (var sqlCmd = new SqlCommand("storedproc", sqlConnection))
    sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
    sqlCmd.Parameters.AddWithValue("@username", int.parse(Textbox1.Text));
    SqlParameter outparameter = new SqlParameter("@password", SqlDbType.NVarChar, 100) { Direction = ParameterDirection.Output };
    sqlCmd.Parameters.Add(outparameter );
    Label1.Text = outparameter .Value;

    Sridhar Thota.
    Editor: DNS Forum.

  • #762683
    Hai Rohit,
    There could be various ways to use out parameter with the stored procedures.
    But the simplest one is the below:

    using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString))
    using (var cmd = new SqlCommand("USP_MyStoredProc", con))
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@p", "yourValue");
    var result = new SqlParameter("@pOut", SqlDbType.NVarChar, 20, ParameterDirection.Output, false, 0, 0, "ColumnName", DataRowVersion.Current, null);
    var outResult = result.Value;

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #762782
    thanks both code is working but i need 3 tier code...what code should my DAL and BAL consist ?

    thanks in advance

Sign In to post your comments