Here is some example code in c#. The Northwind Database has a stored proc called OrderItem which creates an order and returns the OrderID that was created. To access a stored procedure called OrderItem and get back the orderID, you'd to this:
SqlConnection myConn = new SqlConnection();
SqlCommand myCmd = new SqlCommand();
myConn.ConnectionString = "Your connection string here";
myConn.Open();
myCmd.Connection = myConn;
myCmd.CommandText = "OrderItem";
myCmd.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter("@CustomerID", SqlDbType.NVarChar, 5);
myCmd.Parameters.Add(p1);
myCmd.Parameters.Add(p1);
myCmd.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.Int));
myCmd.Parameters.Add(new SqlParameter("@Quantity", SqlDbType.Int));
SqlParameter p2 = new SqlParameter("@OrderID", SqlDbType.Int);
p2.Direction = ParameterDirection.Output;
myCmd.Parameters["@CustomerID"].Value = "PAYNE";
myCmd.Parameters["@ProductID"].Value = 12;
myCmd.Parameters["@Quantity"].Value = 10;
int numrows = myCmd.ExecuteNonQuery();
int OrderID = p2.Value;
MessageBox.Show("Order " + OrderID.ToString() + " has been placed.");
The key to it is the p2.Direction. It needs to be set as an Output parameter.
Hope that helps.
Bob Payne