M
Mike D
I have a table in SQL 2000 with a composite Primary Key on coulumns
Instrument_ID (int) and WeekOf (smalldatetime.) I am running asp on win 2003.
I insert values using a stored procedure from this ASP:
InsertSQL = "Execute osp_insert_Instrument_Schedule "
InsertSQL = InsertSQL & "@UserName = '" & strUserName & "', "
InsertSQL = InsertSQL & "@DateInput = '" & Date() & "', "
InsertSQL = InsertSQL & "@Instrument_ID = " & strInstrument_ID & ", "
InsertSQL = InsertSQL & "@Group_ID = " & strGroup_ID & ", "
InsertSQL = InsertSQL & "@Project_Code = '" & strProject_Code & "', "
InsertSQL = InsertSQL & "@Drug = '" & strDrug & "', "
InsertSQL = InsertSQL & "@WeekOf = '" & strWeekOf & "', "
InsertSQL = InsertSQL & "@Comments = '" & strComments & "'"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open cstInstrScheduleDB
Conn.Execute(InsertSQL)
Conn.Close
Set Conn = Nothing
How do I trap the error? I would like to present some code that says bad
user try again. Where do I trap it?
Thanks
Mike
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Error:
Microsoft OLE DB Provider for SQL Server error '80040e2f'
Violation of PRIMARY KEY constraint 'PK_Tab_Inst_Schedules'. Cannot insert
duplicate key in object 'Tab_Inst_Schedules'.
/ScheduleInputConfirm.asp, line 99
----------------------------------------------------------------------------------------------------------------------------------
Stored procedure:
CREATE PROCEDURE dbo.osp_insert_Instrument_Schedule
@UserName varchar(10),
@DateInput smalldatetime,
@Instrument_ID smallint,
@Group_ID smallint,
@Project_Code varchar(10),
@Drug varchar(50),
@WeekOf varchar(300),
@Comments varchar(2000)
AS
Declare @NewID int
Declare @Spot Smallint
Declare @str varchar(300)
Begin
Set NoCount On
Insert Into Tab_Instr_Sched_Details (Scheduler, ScheduledOn, Instrument_ID,
Group_ID, Project_Code, Drug) Values (@UserName, @DateInput, @Instrument_ID,
@Group_ID, @Project_Code, @Drug)
SELECT @NewID = SCOPE_IDENTITY()
Insert Into Tab_Instr_Sched_Comments (Schedule_ID, Comments) Values (@NewID,
@Comments)
While @Weekof <> ''
Begin
Set @Spot = CharIndex('|', @WeekOf)
If @Spot>0
Begin
Set @str = Left(@WeekOf, @Spot-1)
Set @WeekOf = Right(@WeekOf, Len(@WeekOf)-@Spot)
End
Else
Begin
Set @str = @WeekOf
Set @WeekOf = ''
End
Insert into Tab_Inst_Schedules (Schedule_ID, Instrument_ID, WeekOf) Values
(@NewID, @Instrument_ID, @str)
End
END
SET NOCOUNT OFF
GO
Instrument_ID (int) and WeekOf (smalldatetime.) I am running asp on win 2003.
I insert values using a stored procedure from this ASP:
InsertSQL = "Execute osp_insert_Instrument_Schedule "
InsertSQL = InsertSQL & "@UserName = '" & strUserName & "', "
InsertSQL = InsertSQL & "@DateInput = '" & Date() & "', "
InsertSQL = InsertSQL & "@Instrument_ID = " & strInstrument_ID & ", "
InsertSQL = InsertSQL & "@Group_ID = " & strGroup_ID & ", "
InsertSQL = InsertSQL & "@Project_Code = '" & strProject_Code & "', "
InsertSQL = InsertSQL & "@Drug = '" & strDrug & "', "
InsertSQL = InsertSQL & "@WeekOf = '" & strWeekOf & "', "
InsertSQL = InsertSQL & "@Comments = '" & strComments & "'"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open cstInstrScheduleDB
Conn.Execute(InsertSQL)
Conn.Close
Set Conn = Nothing
How do I trap the error? I would like to present some code that says bad
user try again. Where do I trap it?
Thanks
Mike
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Error:
Microsoft OLE DB Provider for SQL Server error '80040e2f'
Violation of PRIMARY KEY constraint 'PK_Tab_Inst_Schedules'. Cannot insert
duplicate key in object 'Tab_Inst_Schedules'.
/ScheduleInputConfirm.asp, line 99
----------------------------------------------------------------------------------------------------------------------------------
Stored procedure:
CREATE PROCEDURE dbo.osp_insert_Instrument_Schedule
@UserName varchar(10),
@DateInput smalldatetime,
@Instrument_ID smallint,
@Group_ID smallint,
@Project_Code varchar(10),
@Drug varchar(50),
@WeekOf varchar(300),
@Comments varchar(2000)
AS
Declare @NewID int
Declare @Spot Smallint
Declare @str varchar(300)
Begin
Set NoCount On
Insert Into Tab_Instr_Sched_Details (Scheduler, ScheduledOn, Instrument_ID,
Group_ID, Project_Code, Drug) Values (@UserName, @DateInput, @Instrument_ID,
@Group_ID, @Project_Code, @Drug)
SELECT @NewID = SCOPE_IDENTITY()
Insert Into Tab_Instr_Sched_Comments (Schedule_ID, Comments) Values (@NewID,
@Comments)
While @Weekof <> ''
Begin
Set @Spot = CharIndex('|', @WeekOf)
If @Spot>0
Begin
Set @str = Left(@WeekOf, @Spot-1)
Set @WeekOf = Right(@WeekOf, Len(@WeekOf)-@Spot)
End
Else
Begin
Set @str = @WeekOf
Set @WeekOf = ''
End
Insert into Tab_Inst_Schedules (Schedule_ID, Instrument_ID, WeekOf) Values
(@NewID, @Instrument_ID, @str)
End
END
SET NOCOUNT OFF
GO