Click here to Skip to main content
15,902,492 members
Home / Discussions / Database
   

Database

 
AnswerRe: Convert getdate() Pin
Szemi9025-Jan-07 22:59
Szemi9025-Jan-07 22:59 
QuestionCDaoDatabase Create Field Pin
DKScherpy25-Jan-07 9:58
DKScherpy25-Jan-07 9:58 
QuestionIncrement Field Value Pin
achimera25-Jan-07 9:39
achimera25-Jan-07 9:39 
AnswerRe: Increment Field Value Pin
PIEBALDconsult25-Jan-07 9:55
mvePIEBALDconsult25-Jan-07 9:55 
GeneralRe: Increment Field Value Pin
achimera25-Jan-07 10:06
achimera25-Jan-07 10:06 
Questioncall function from select join Pin
montu337725-Jan-07 3:51
montu337725-Jan-07 3:51 
AnswerRe: call function from select join Pin
Paddy Boyd25-Jan-07 4:29
Paddy Boyd25-Jan-07 4:29 
QuestionSCOPE_IDENTITY() Always Returning 1 Pin
Farm Developer25-Jan-07 0:43
Farm Developer25-Jan-07 0:43 
I have the Stored Procedure below which I run using the code below that but each time I run the procedure the row gets added to the table but the @Identity parameter is always the value 1. There is a column on the Invoice table called InvoiceID which has Identity set as Yes.

Am I doing something wrong?

Thanks
Paul

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <author,,name>
-- Create date: <create date,,="">
-- Description: <description,,>
-- =============================================
ALTER PROCEDURE [dbo].[InsertInvoice]
-- Add the parameters for the stored procedure here
@IClientID int
,@InvoiceNumber varchar(15)
,@InvoiceDate datetime
,@PaymentStatus tinyint
,@Description varchar(255)
,@InvoiceNotes text
,@ICustomCheck1 bit
,@ICustomCheck2 bit
,@ICustomCheck3 bit
,@ICustomCheck4 bit
,@ICustomCheck5 bit
,@ICustomCheck6 bit
,@IsAgent bit
,@Identity int OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
INSERT INTO [BreedSociety].[dbo].[Invoice]
([IClientID]
,[InvoiceNumber]
,[InvoiceDate]
,[PaymentStatus]
,[Description]
,[InvoiceNotes]
,[ICustomCheck1]
,[ICustomCheck2]
,[ICustomCheck3]
,[ICustomCheck4]
,[ICustomCheck5]
,[ICustomCheck6]
,[IsAgent])
VALUES
(@IClientID
,@InvoiceNumber
,@InvoiceDate
,@PaymentStatus
,@Description
,@InvoiceNotes
,@ICustomCheck1
,@ICustomCheck2
,@ICustomCheck3
,@ICustomCheck4
,@ICustomCheck5
,@ICustomCheck6
,@IsAgent)

SET @Identity = SCOPE_IDENTITY()
END


SqlCommand cmd = dCon.CreateCommand();
cmd.CommandText = "InsertClient";
cmd.CommandType = System.Data.CommandType.StoredProcedure;

cmd.Parameters.Add("@HoldingNumber", SqlDbType.VarChar).Value = client.HoldingNumber;
cmd.Parameters.Add("@TradingTitle", SqlDbType.VarChar).Value = client.TradingTitle;
cmd.Parameters.Add("@Surname", SqlDbType.VarChar).Value = client.Surname;
cmd.Parameters.Add("@ContactName", SqlDbType.VarChar).Value = client.ContactName;
cmd.Parameters.Add("@Address1", SqlDbType.VarChar).Value = client.Address1;
cmd.Parameters.Add("@Address2", SqlDbType.VarChar).Value = client.Address2;
cmd.Parameters.Add("@Address3", SqlDbType.VarChar).Value = client.Address3;
cmd.Parameters.Add("@Address4", SqlDbType.VarChar).Value = client.Address4;
cmd.Parameters.Add("@Postcode", SqlDbType.VarChar).Value = client.Postcode;
cmd.Parameters.Add("@Tel", SqlDbType.VarChar).Value = client.Tel;
cmd.Parameters.Add("@Tel2", SqlDbType.VarChar).Value = client.Tel2;
cmd.Parameters.Add("@Mobile", SqlDbType.VarChar).Value = client.Mobile;
cmd.Parameters.Add("@Fax", SqlDbType.VarChar).Value = client.Fax;
cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = client.Email;
cmd.Parameters.Add("@Agent", SqlDbType.TinyInt).Value = client.Agent;
cmd.Parameters.Add("@CTSUsername", SqlDbType.VarChar).Value = client.CTSUsername;
cmd.Parameters.Add("@CTSPassword", SqlDbType.VarChar).Value = client.CTSPassword;
cmd.Parameters.Add("@LMeNTRY", SqlDbType.Bit).Value = client.LMeNTRY;
cmd.Parameters.Add("@FarmMatters", SqlDbType.Bit).Value = client.FarmMatters;
cmd.Parameters.Add("@ClientNotes", SqlDbType.VarChar).Value = client.ClientNotes;
cmd.Parameters.Add("@Support", SqlDbType.TinyInt).Value = client.Support;
cmd.Parameters.Add("@Licenes", SqlDbType.Int).Value = client.Licenes;
cmd.Parameters.Add("@IsBureau", SqlDbType.Bit).Value = client.IsBureau;
cmd.Parameters.Add("@OperatingSystem", SqlDbType.TinyInt).Value = client.OperatingSystem;
cmd.Parameters.Add("@SBI", SqlDbType.VarChar).Value = client.SBI;
cmd.Parameters.Add("@CustomCheck1", SqlDbType.Bit).Value = client.CustomCheck1;
cmd.Parameters.Add("@CustomCheck2", SqlDbType.Bit).Value = client.CustomCheck2;
cmd.Parameters.Add("@CustomCheck3", SqlDbType.Bit).Value = client.CustomCheck3;
cmd.Parameters.Add("@CustomCheck4", SqlDbType.Bit).Value = client.CustomCheck4;
cmd.Parameters.Add("@CustomCheck5", SqlDbType.Bit).Value = client.CustomCheck5;
cmd.Parameters.Add("@CustomCheck6", SqlDbType.Bit).Value = client.CustomCheck6;
cmd.Parameters.Add("@Identity", SqlDbType.Int);

cmd.Parameters["@Identity"].Direction = System.Data.ParameterDirection.Output;


if(isClosed) dCon.Open();
cmd.ExecuteNonQuery();
if(isClosed) dCon.Close();

return Convert.ToInt32(cmd.Parameters["@Identity"].Value);
AnswerRe: SCOPE_IDENTITY() Always Returning 1 Pin
Jon Sagara25-Jan-07 10:23
Jon Sagara25-Jan-07 10:23 
GeneralRe: SCOPE_IDENTITY() Always Returning 1 Pin
Farm Developer25-Jan-07 21:42
Farm Developer25-Jan-07 21:42 
GeneralRe: SCOPE_IDENTITY() Always Returning 1 Pin
Jon Sagara26-Jan-07 1:52
Jon Sagara26-Jan-07 1:52 
AnswerRe: SCOPE_IDENTITY() Always Returning 1 Pin
Farm Developer26-Jan-07 4:09
Farm Developer26-Jan-07 4:09 
QuestionProblem In Multi Conditioned SQL: Pin
Shahzad.Aslam24-Jan-07 22:14
Shahzad.Aslam24-Jan-07 22:14 
AnswerRe: Problem In Multi Conditioned SQL: Pin
Parwej Ahamad24-Jan-07 22:27
professionalParwej Ahamad24-Jan-07 22:27 
AnswerRe: Problem In Multi Conditioned SQL: Pin
Pete O'Hanlon24-Jan-07 22:53
mvePete O'Hanlon24-Jan-07 22:53 
GeneralRe: Problem In Multi Conditioned SQL: Pin
Shahzad.Aslam24-Jan-07 23:32
Shahzad.Aslam24-Jan-07 23:32 
GeneralRe: Problem In Multi Conditioned SQL: Pin
Colin Angus Mackay24-Jan-07 23:53
Colin Angus Mackay24-Jan-07 23:53 
GeneralRe: Problem In Multi Conditioned SQL: Pin
Shahzad.Aslam25-Jan-07 0:18
Shahzad.Aslam25-Jan-07 0:18 
GeneralRe: Problem In Multi Conditioned SQL: Pin
Pete O'Hanlon25-Jan-07 0:57
mvePete O'Hanlon25-Jan-07 0:57 
GeneralRe: Problem In Multi Conditioned SQL: Pin
Mike Dimmick25-Jan-07 1:31
Mike Dimmick25-Jan-07 1:31 
GeneralRe: Problem In Multi Conditioned SQL: Pin
Shahzad.Aslam25-Jan-07 19:08
Shahzad.Aslam25-Jan-07 19:08 
AnswerRe: Problem In Multi Conditioned SQL: Pin
Mike Dimmick25-Jan-07 1:21
Mike Dimmick25-Jan-07 1:21 
QuestionWant to Display 2 columns result as one column(Urgent) Pin
priya_p23324-Jan-07 19:30
priya_p23324-Jan-07 19:30 
AnswerRe: Want to Display 2 columns result as one column(Urgent) [modified] Pin
Parwej Ahamad24-Jan-07 20:22
professionalParwej Ahamad24-Jan-07 20:22 
GeneralRe: Want to Display 2 columns result as one column(Urgent) Pin
priya_p23324-Jan-07 20:59
priya_p23324-Jan-07 20:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.