title: C# return double value from stored procedure
body: <p>I want to return a <code>double</code> value from a stored procedure so I can call it from a form and multiplication its value in the value of the text box.</p>
  
  <p>My stored procedure looks like this:</p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER PROCEDURE [dbo].[Get_Weight]
      @ID INT,
      @Weight FLOAT OUTPUT
  AS
      SELECT @Weight = [Weight] 
      FROM [Item]
      WHERE ID_Item = @ID
  </code></pre>
  
  <p>This is my data access layer class:</p>
  
  <pre><code>class DataAccessLayer
  {
      SqlConnection sqlconnection;
  
      public DataAccessLayer()
      {
          PL.FRM_LOGIN frm = new PL.FRM_LOGIN();
          sqlconnection = new SqlConnection("Server='"+System.Environment.MachineName+"';DataBase='"+frm.txtDataBase.Text+"';Integrated Security=true");          
      }
  
      // Method to open the connection
      public void Open()
      {
          if(sqlconnection.State != ConnectionState.Open)
          {
              sqlconnection.Open();
          }
      }
  
      // Method to close the connection
      public void Close()
      {
          if(sqlconnection.State == ConnectionState.Open)
          {
              sqlconnection.Close();
          }
      }
  
      // Method to read data from database
      public DataTable SelectData(string stored_procedure, SqlParameter[] param)
      {
          SqlCommand sqlcmd = new SqlCommand();
          sqlcmd.CommandType = CommandType.StoredProcedure;
          sqlcmd.CommandText = stored_procedure;
          sqlcmd.Connection = sqlconnection;
  
          if (param != null)
          {
              sqlcmd.Parameters.AddRange(param);
          }
  
          SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
          DataTable dt = new DataTable();
          da.Fill(dt);
  
          return dt;
      }
  
      // Method to insert, update and delete data from database
      public void ExecuteCommand(string stored_procedure, SqlParameter[] param)
      {
          SqlCommand sqlcmd = new SqlCommand();
          sqlcmd.CommandType = CommandType.StoredProcedure;
          sqlcmd.CommandText = stored_procedure;
          sqlcmd.Connection = sqlconnection;
  
          if (param != null)
          {         
              sqlcmd.Parameters.AddRange(param);           
          }
  
          sqlcmd.ExecuteNonQuery();
      }
  }
  </code></pre>
  
  <p>I want to create a class in the business layer with a method that can return the value - for example</p>
  
  <pre><code>public void Get_Weight(int ID, double UWeight)
  {
      DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
      DAL.Open();
  
      SqlParameter[] param = new SqlParameter[2];
  
      param[0] = new SqlParameter("@ID", SqlDbType.Int);
      param[0].Value = ID;
  
      param[1] = new SqlParameter("@Weight", SqlDbType.Float);
      param[1].Value = UWeight;
      param[1].Direction = ParameterDirection.Output;
  
      DAL.ExecuteCommand("Get_Weight", param);
      DAL.Close();
  }
  </code></pre>
  
  <p>And after that, I call that method from the form</p>
  
  <pre><code>void CalculateWeight()
  {           
      if (txtLength.Text != string.Empty &amp;&amp; cmbName.Text != null)
      {
          txtWeight.Text = (Convert.ToInt32(txtLength.Text) *(//the code)).ToString();
      }
  }
  </code></pre>
  
  <p>Please help me</p>