views:

70

answers:

1

Good Afternoon All,

I have a wizard control that contains 20 textboxes for part numbers and another 20 for quantities. I want the part numbers and quantities loaded into the following table:

USE [Diel_inventory]
GO
/****** Object:  Table [dbo].[QUOTEDETAILPARTS]    Script Date: 05/09/2010 16:26:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[QUOTEDETAILPARTS](
[QuoteDetailPartID] [int] IDENTITY(1,1) NOT NULL,
[QuoteDetailID] [int] NOT NULL,
[PartNumber] [float] NULL,
[Quantity] [int] NULL,
CONSTRAINT [pkQuoteDetailPartID] PRIMARY KEY CLUSTERED 
(
[QuoteDetailPartID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[QUOTEDETAILPARTS]  WITH CHECK ADD  CONSTRAINT [fkQuoteDetailID] FOREIGN KEY([QuoteDetailID])
REFERENCES [dbo].[QUOTEDETAIL] ([ID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

Here's the snippet from my sproc for this insert:

set @ID=scope_identity()

Insert into dbo.QuoteDetailParts
(QuoteDetailPartID, QuoteDetailID, PartNumber, Quantity)
values (@ID, @QuoteDetailPartID, @PartNumber, @Quantity)

When I run the ASPX page, I receive an error that there are too many arguments specified for my stored procedure. I understand why I'm getting the error, given the above table layout. However, I need help in structuring my insert syntax to look for values in all 20 PartNumber and Quantity field pairs.

Thanks, Sid

+2  A: 

Your QuoteDetailPartID is an IDENTITY field - you cannot insert a value into an IDENTITY field (except if you explicitly enable that - only do that if you really really must).

You should change your stored proc to use:

INSERT INTO dbo.QuoteDetailParts(QuoteDetailID, PartNumber, Quantity)
VALUES(@QuoteDetailID, @PartNumber, @Quantity)

You can then get back the newly inserted QuoteDetailPartID by inspecting the SCOPE_IDENTITY() function:

SET @QuoteDetailPartID = SCOPE_IDENTITY()

I wouldn't make your stored proc go "look for" the twenty fields - do that in your wizard logic, in your C# or VB.NET code, and call the stored proc to insert a single QuoteDetailPart as many times as you really need (you might only have 3 detail parts to insert, after all)

marc_s