run stored sql procedure with output parameter from c#
===

I realize that this question has been answered before, and I have looked through the answers, trying to find the error of my ways, but am at a standstill. I have the following stored procedure that should return a unique key. 

    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    ALTER   PROCEDURE [dbo].[newid] @tablename AS CHAR(10), @fieldname AS CHAR(15) = '', @ioffset AS INT, @theID as int = 0 output 
    AS
    BEGIN
      SET NOCOUNT ON
 
     DECLARE @value AS INT
     IF @ioffset < 1 SET @ioffset = 1
     IF LEN(@fieldname) > 0
      BEGIN
        UPDATE id SET @value = CONVERT(INT,cvalue)+@ioffset-1, cvalue = CONVERT(CHAR,(CONVERT(INT,cvalue)+@ioffset)) WHERE UPPER(ctablename) = UPPER(@tablename) AND UPPER(cfieldname) = UPPER(@fieldname)
       SELECT @value
      END
     ELSE
      BEGIN
       UPDATE id SET @value = CONVERT(INT,cvalue)+@ioffset-1, cvalue = CONVERT(CHAR,(CONVERT(INT,cvalue)+@ioffset)) WHERE UPPER(ctablename) = UPPER(@tablename)
       SELECT @value 
      End
     SET NOCOUNT OFF
    set @theID = @value
    END

I am using the following code to try to access the procedure:

    using(SqlConnection connection = new SqlConnection(connectionString))
    using(SqlCommand command = new SqlCommand("dbo.NewID", connection)
         { CommandType = CommandType.StoredProcedure } )
    {
         command.Parameters.Add( new SqlParameter("@tablename",table));
         command.Parameters.Add( new SqlParameter("@fieldname",field));
         command.Parameters.Add( new SqlParameter("@ioffset",1));
         SqlParameter key = new SqlParameter("@theID", SqlDbType.Int);
         key.Direction = ParameterDirection.Output;
         command.Parameters.Add(key);

         connection.Open();
         result = command.ExecuteNonQuery();
         connection.Close();
    }

key.Value is coming back empty, and result is -1, insinuating that there was an error running the procedure. If anyone sees what I might be doing wrong, I would greatly appreciate the assistance. 

Just a note: I am not able to edit the actual procedure, as there are several classes that already make use of it.

Thank you very much in advance for any assistance.