You probably need to set the direction for your OrderId parameter.
On Tue, Jan 12, 2010 at 7:35 PM, Richard Walsh <[email protected]> wrote: > I am working on a stored procedure, Which inserts a record in one > table, then one in another table, grabbing a IDENTITY value and > updating the previous record. > > This all works, but the next part I am working on is the part where I > am having trouble. I am trying to return the @@IDENTITY as a value for > a page redirect after successful insertion. > > This is the procedure > @orderID int OUT, > -...@relid int output, > @order_name nvarchar(50), > @order_type int, > @order_customer nvarchar(155), > @order_account nvarchar(30), > @order_ppc nvarchar(65), > @order_csr nvarchar(65), > @order_rep nvarchar(65) AS > SET NOCOUNT ON > INSERT INTO [OMS].[dbo].[order_writeup] ([order_name],[order_type], > [order_customer],[order_account], [order_ppc], [order_csr], > [order_rep]) > VALUES (@order_name, @order_type, @order_customer, @order_account, > @order_ppc, @order_csr, @order_rep) > SET @orderID=SCOPE_IDENTITY() > INSERT INTO [OMS].[dbo].[order_master] ([order_id]) values > (SCOPE_IDENTITY()) > UPDATE order_writeup SET relative_id = @@IDENTITY WHERE ID = @orderID > SET NOCOUNT OFF > RETURN @@IDENTITY > > This is the webservice command > [WebMethod] > public int CreateProject2(int ordID,string PName, int ordertype, > string clientname, string accountno, string ppc, string csr, string > salesrep) > { > Int32 result = 0; > using (SqlConnection conn = new SqlConnection > ("server=WWAPPS;database=OMS;uid=sa;pwd=sqluser")) > { > SqlCommand cmd = new SqlCommand("createProjects", conn); > cmd.CommandType = CommandType.StoredProcedure; > cmd.Parameters.Add("@orderID", SqlDbType.Int).Value=ordID; > cmd.Parameters.Add("@order_name", SqlDbType.VarChar, > 50).Value=PName; > cmd.Parameters.Add("@order_type", > SqlDbType.Int).Value=ordertype; > cmd.Parameters.Add("@order_customer", SqlDbType.VarChar, > 155).Value=clientname; > cmd.Parameters.Add("@order_account", SqlDbType.VarChar, > 30).Value=accountno; > cmd.Parameters.Add("@order_ppc", SqlDbType.VarChar, > 65).Value=ppc; > cmd.Parameters.Add("@order_csr", SqlDbType.VarChar, > 65).Value=csr; > cmd.Parameters.Add("@order_rep", SqlDbType.VarChar, > 65).Value=salesrep; > conn.Open(); > cmd.ExecuteNonQuery(); > result = Convert.ToInt32(cmd.Parameters > ["@orderID"].Value); > } > return result; > } >
