From: Paul on
Hi,
I have the next stored procedure in Sql Server 2008:

CREATE PROCEDURE [dbo].[GetNumTiquet]
@IdEmpresa int,
@NumTiquet int OUTPUT
AS
BEGIN
SET NOCOUNT ON;

UPDATE ConfGen
SET @NumTiquet=NumTiquet = (SELECT MAX(NumTiquet) +1 FROM ConfGen)
WHERE Id = @IdEmpresa
END

If i execute this stored procedure with Sql Server 2008 all is ok.
But how can i call this stored procedure with c#?

Thanks
From: Mr. Arnold on
Paul wrote:
> Hi,
> I have the next stored procedure in Sql Server 2008:
>
> CREATE PROCEDURE [dbo].[GetNumTiquet]
> @IdEmpresa int,
> @NumTiquet int OUTPUT
> AS
> BEGIN
> SET NOCOUNT ON;
>
> UPDATE ConfGen
> SET @NumTiquet=NumTiquet = (SELECT MAX(NumTiquet) +1 FROM ConfGen)
> WHERE Id = @IdEmpresa
> END
>
> If i execute this stored procedure with Sql Server 2008 all is ok.
> But how can i call this stored procedure with c#?
>
> Thanks

<http://www.google.com/#hl=en&q=how+to+get+output+parameter+from+stored+procedure+ado.net&aq=f&aqi=&aql=&oq=how+to+get+output+parameter+from+stored+procedure+ado.net&gs_rfai=&fp=c0cfdbfb1e48170b>
From: Arne Vajhøj on
On 01-07-2010 11:39, Paul wrote:
> I have the next stored procedure in Sql Server 2008:
>
> CREATE PROCEDURE [dbo].[GetNumTiquet]
> @IdEmpresa int,
> @NumTiquet int OUTPUT
> AS
> BEGIN
> SET NOCOUNT ON;
>
> UPDATE ConfGen
> SET @NumTiquet=NumTiquet = (SELECT MAX(NumTiquet) +1 FROM ConfGen)
> WHERE Id = @IdEmpresa
> END
>
> If i execute this stored procedure with Sql Server 2008 all is ok.
> But how can i call this stored procedure with c#?

Something like (untested):

SqlCommand cmd = new SqlCommand("dbo.GetNumTiquet", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm1 = new SqlParameter("@IdEmpresa", SqlDbType.Int);
cmd.Parameters.Add(prm1);
SqlParameter prm2 = new SqlParameter("@NumTiquet", SqlDbType.Int);
prm2.Direction = ParameterDirection.Output;
cmd.Parameters.Add(prm2);
cmd.Parameters["@IdEmpresa"].Value = v;
cmd.ExecuteNonQuuery();
int res = (int)cmd.Parameters["@NumTiquet"].Value);

Arne
From: Arne Vajhøj on
On 01-07-2010 17:52, Arne Vajh�j wrote:
> On 01-07-2010 11:39, Paul wrote:
>> I have the next stored procedure in Sql Server 2008:
>>
>> CREATE PROCEDURE [dbo].[GetNumTiquet]
>> @IdEmpresa int,
>> @NumTiquet int OUTPUT
>> AS
>> BEGIN
>> SET NOCOUNT ON;
>>
>> UPDATE ConfGen
>> SET @NumTiquet=NumTiquet = (SELECT MAX(NumTiquet) +1 FROM ConfGen)
>> WHERE Id = @IdEmpresa
>> END
>>
>> If i execute this stored procedure with Sql Server 2008 all is ok.
>> But how can i call this stored procedure with c#?
>
> Something like (untested):
>
> SqlCommand cmd = new SqlCommand("dbo.GetNumTiquet", con);
> cmd.CommandType = CommandType.StoredProcedure;
> SqlParameter prm1 = new SqlParameter("@IdEmpresa", SqlDbType.Int);
> cmd.Parameters.Add(prm1);
> SqlParameter prm2 = new SqlParameter("@NumTiquet", SqlDbType.Int);
> prm2.Direction = ParameterDirection.Output;
> cmd.Parameters.Add(prm2);
> cmd.Parameters["@IdEmpresa"].Value = v;
> cmd.ExecuteNonQuuery();
> int res = (int)cmd.Parameters["@NumTiquet"].Value);

Note that the use of:

SELECT MAX()+1

usually is the wrong approach and instead SCOPE_IDENTITY() should
be used in the following SQL statements.

Arne
From: Paul on
On 1 jul, 23:54, Arne Vajhøj <a...(a)vajhoej.dk> wrote:
> On 01-07-2010 17:52, Arne Vajh j wrote:
>
>
>
>
>
> > On 01-07-2010 11:39, Paul wrote:
> >> I have the next stored procedure in Sql Server 2008:
>
> >> CREATE PROCEDURE [dbo].[GetNumTiquet]
> >> @IdEmpresa int,
> >> @NumTiquet int OUTPUT
> >> AS
> >> BEGIN
> >> SET NOCOUNT ON;
>
> >> UPDATE ConfGen
> >> SET @NumTiquet=NumTiquet = (SELECT MAX(NumTiquet) +1 FROM ConfGen)
> >> WHERE Id = @IdEmpresa
> >> END
>
> >> If i execute this stored procedure with Sql Server 2008 all is ok.
> >> But how can i call this stored procedure with c#?
>
> > Something like (untested):
>
> > SqlCommand cmd = new SqlCommand("dbo.GetNumTiquet", con);
> > cmd.CommandType = CommandType.StoredProcedure;
> > SqlParameter prm1 = new SqlParameter("@IdEmpresa", SqlDbType.Int);
> > cmd.Parameters.Add(prm1);
> > SqlParameter prm2 = new SqlParameter("@NumTiquet", SqlDbType.Int);
> > prm2.Direction = ParameterDirection.Output;
> > cmd.Parameters.Add(prm2);
> > cmd.Parameters["@IdEmpresa"].Value = v;
> > cmd.ExecuteNonQuuery();
> > int res = (int)cmd.Parameters["@NumTiquet"].Value);
>
> Note that the use of:
>
> SELECT MAX()+1
>
> usually is the wrong approach and instead SCOPE_IDENTITY() should
> be used in the following SQL statements.
>
> Arne- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -

Hi,
I don't understant.
What do you menan with SCOPE_INDENTITY() with this example?
Thanks