stored procedure using c#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    stored procedure using c#?

    hai all,
    i am new to asp.net. by using vs 2005 i want to write a stored procedure to save and retrieve data from database. kindly guide me to do this.
    thanx in advance.
  • ghousebarq
    New Member
    • May 2007
    • 5

    #2
    Originally posted by nirmalsingh
    hai all,
    i am new to asp.net. by using vs 2005 i want to write a stored procedure to save and retrieve data from database. kindly guide me to do this.
    thanx in advance.
    Hi,
    The below link should help you.

    Comment

    • Shivam Varshi
      New Member
      • Jan 2008
      • 1

      #3
      Originally posted by nirmalsingh
      hai all,
      i am new to asp.net. by using vs 2005 i want to write a stored procedure to save and retrieve data from database. kindly guide me to do this.
      thanx in advance.
      Dear,
      you can use this codes for your queries..

      public class ExecuteSQLComma nd
      {
      string strCommandName;
      SqlCommand objCommand;
      SqlParameter objParam;
      //Set the Connection String to the Database
      SqlConnection objConnection = new SqlConnection(" server=localhos t;uid=sa;pwd=;I nitial Catalog=Home");
      try
      {
      //Name of the Stored Procedure to be executed
      strCommandName = "spStoredProced ureName";
      objCommand = new SqlCommand(strC ommandName, objConnection);
      objCommand.Comm andType = CommandType.Sto redProcedure;
      //Set the Parameters
      objParam = objCommand.Para meters.Add(new SqlParameter("@ VariableOne", SqlDbType.VarCh ar, 50));
      objParam.Direct ion = ParameterDirect ion.Input;
      objParam.Value = strVariableOne;
      objParam = objCommand.Para meters.Add(new SqlParameter("@ VariableTwo", SqlDbType.Int)) ;
      objParam.Direct ion = ParameterDirect ion.Output;
      objCommand.Conn ection.Open();
      objCommand.Exec uteNonQuery();
      //'Get the Out parameter from the Stored Procedure
      intValueReturn = Convert.ToInt32 ((objCommand.Pa rameters["@getValueVaria bleName"].Value.ToString ()));

      }

      catch(Exception ex)
      {
      throw ex;
      }

      finally
      {
      if ( objConnection.S tate == ConnectionState .Open) objConnection.C lose(); objReader.Close ();
      }



      }

      Comment

      • dhanashivam
        New Member
        • Mar 2007
        • 31

        #4
        hi

        did u get any reply for it?

        regards,
        dhanasekaran.g

        Comment

        Working...