问:我制作了一个由多个带有主键的表组成的视图。我在 ASP.NET 中使用 GridView 来更新和删除数据库中的一行。该行由两个不同的表组成。我将如何使用 ASP.NET 中的 GridView 更新和删除它?我很难弄清楚,因为我所做的每一次尝试,SQL Server 都会说“无法更新视图,因为它正在访问多个表”。
事实证明,当 VIEW 由多个表组成时,您无法在 GridView 的“选择数据源”中自动生成 UPDATE 和 DELETE 语句。
请帮帮我:(
CREATE VIEW [dbo].[viewProcedureWithPrice]
AS
SELECT dbo.[PROCEDURE].ProcedureID, dbo.[PROCEDURE].Name, dbo.[PROCEDURE].Type, dbo.[PROCEDURE].Status, dbo.PRICE_HISTORY.Price,
dbo.PRICE_HISTORY.EffectivityDate
FROM dbo.[PROCEDURE] INNER JOIN
dbo.PRICE_HISTORY ON dbo.[PROCEDURE].ProcedureID = dbo.PRICE_HISTORY.ProcedureID
GO
CREATE TABLE [dbo].[PROCEDURE](
[ProcedureID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](100) NULL,
[Type] [varchar](100) NULL,
[Status] [varchar](20) NULL,
CONSTRAINT [PK_PROCEDURE] PRIMARY KEY CLUSTERED
(
[ProcedureID] 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
CREATE TABLE [dbo].[PRICE_HISTORY](
[HistoryID] [int] IDENTITY(1,1) NOT NULL,
[ProcedureID] [int] NULL,
[Price] [decimal](10, 2) NULL,
[EffectivityDate] [date] NULL,
CONSTRAINT [PK_PRICE_HISTORY] PRIMARY KEY CLUSTERED
(
[HistoryID] 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].[PRICE_HISTORY] WITH CHECK ADD CONSTRAINT [FK_PRICE_HISTORY_PROCEDURE] FOREIGN KEY([ProcedureID])
REFERENCES [dbo].[PROCEDURE] ([ProcedureID])
GO
ALTER TABLE [dbo].[PRICE_HISTORY] CHECK CONSTRAINT [FK_PRICE_HISTORY_PROCEDURE]
GO