M
Mitri Dahdaly
Hi all
I hope you can help, I am in the process of converting my access based
application in to an access data project with SQL Server. I begain doing
this a few years ago and then gave up but I am back at it again. When I
originally started I was using Access 2000 with SQL Server 7. I am now using
Access 2003 and SQL Server 2005. I have a situation where I had something
working in the old versions of access and SQL server but are refusing to
work in the current versions. I have created a stored procedure that inserts
some data in access I have the following code:
Dim rst As New ADODB.Recordset
Dim objCommand As New ADODB.Command
objCommand.ActiveConnection = dbs
'Stored Procedure Name
objCommand.CommandText = "Insert_Res"
objCommand.CommandType = adCmdStoredProc
'objCommand.Parameters.Refresh
objCommand.Parameters("@CustomerID") = Me!CustomerID
// More parameters go here
Set rst = objCommand.Execute
Me.ReservationID = rst(0)
The me.reservationid line cause an error 3265 run time error. My stored
procedure looks like this:
USE [LCS_Master_2003SQL]
GO
/****** Object: StoredProcedure [dbo].[Insert_Res] Script Date: 11/25/2007
13:35:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[Insert_Res]
(
-- Declare all Inputs
-- Reservation Details
----------------------------------------------------------------------------------------
@CustomerID varchar(10),
@FirstName varchar(20),
@LastName varchar(30),
@PickupAddress varchar(30),
@PickupSuffix varchar(4),
@PickupCity varchar(30),
@PickupRegion varchar(2),
@PickupPostalCode varchar(15),
@PickupPhone varchar(15),
@PickupZone varchar(10),
@PickupDate datetime,
@PickupIntersection varchar(100),
@DropoffAddress varchar(30),
@DropoffSuffix varchar(4),
@DropoffCity varchar(30),
@DropoffRegion varchar(2),
@DropoffPostalCode varchar(10),
@DropoffPhone varchar(15),
@DropoffZone int,
@DismissDate datetime = '',
@PaymentMethod varchar(10),
@CreditCardNumber varchar(20),
@ExpiryDate varchar(22),
@InputDate datetime,
@LastActivityDate datetime,
@UserID varchar(30),
@Passengers smallint,
@WakeupDate varchar(22),
@ContactFirstName varchar(50),
@ContactName varchar(30),
@ContactPhone varchar(15),
@contactEmail varchar(50),
@emailc bit,
@PurchaseOrder varchar(15),
@Appartment varchar(5),
@Buzzer varchar(5),
@InitialUserID varchar(30),
@Notes varchar(100),
@psemail varchar(50),
@email bit,
@PickupFlight varchar(50),
@PickupAirline varchar(50),
@PickupFlightTime varchar(50),
@DropoffFlight varchar(50),
@DropoffAirline varchar(50),
@DropoffFlightTime varchar(50),
@Ref as varchar(3),
--This will be used for Dynamic SQL to insert records for Dispatch subtable
--@Disp varchar(2000)
--@MXRSID varchar(10)
@VehicleType int
--@HourlyRate varchar(10),
--@UserID varcahr(30),
--@Hours smallint
-----------------------------------------------------------------------------------------
output
)
As
-- Declare all Variables
Declare
@MXRSID varchar(10),
@MXRSIDPRE INTEGER,
@MXRSINT INTEGER,
@varvchrError varchar(100), -- keeps the error message.
--@ResPre varchar(2),
@VT varchar(10),
@ResID int
--SELECT @ResPre = Reference
--FROM MyCompany
SELECT @MXRSID = MAX(ReservationID)
FROM dbo.Reservations
where ReservationID like @Ref + '%'
if @MXRSID is Null
set @MXRSID = @Ref + '000000'
set @MXRSIDPRE = CAST(SUBSTRING(@MXRSID, 3, 6 ) AS INT)
set @MXRSINT = @MXRSIDPRE + 1
if Len(@MXRSINT) < 6
set @MXRSID = @MXRSINT
if Len(@MXRSINT) = 5
set @MXRSID = @Ref + '0' + CAST(@MXRSINT AS VARCHAR(5))
if Len(@MXRSINT) = 4
set @MXRSID = @Ref + '00' + CAST(@MXRSINT AS VARCHAR(4))
if Len(@MXRSINT) = 3
set @MXRSID = @Ref + '000' + CAST(@MXRSINT AS VARCHAR(3))
if Len(@MXRSINT) = 2
set @MXRSID = @Ref + '0000' + CAST(@MXRSINT AS VARCHAR(2))
if Len(@MXRSINT) = 1
set @MXRSID = @Ref + '00000' + CAST(@MXRSINT AS VARCHAR(1))
if Len(@MXRSINT) = 0
set @MXRSID = @Ref + '000000'
begin transaction INS_RES_ID
INSERT INTO dbo.Reservations
(ReservationID,
CustomerID,
FirstName,
LastName,
PickupAddress,
PickupSuffix,
PickupCity,
PickupRegion,
PickupPostalCode,
PickupPhone,
PickupZone,
PickupDate,
PickupIntersection,
DropoffAddress,
DropoffSuffix,
DropoffCity,
DropoffRegion,
DropoffPostalCode,
DropoffPhone,
DropoffZone,
PaymentMethod,
CreditCardNumber,
ExpiryDate,
InputDate,
LastActivityDate,
UserID,
Passengers,
WakeupDate,
ContactName,
ContactPhone,
PurchaseOrder,
Appartment,
Buzzer,
InitialUserID,
Notes,
Passemail,
email,
PickupFlight,
PickupAirline,
PickupFlightTime,
DropoffFlight,
DropoffAirline,
DropoffFlightTime)
Values(@MXRSID,
@CustomerID,
@FirstName,
@LastName,
@PickupAddress,
@PickupSuffix,
@PickupCity,
@PickupRegion,
@PickupPostalCode,
@PickupPhone,
@PickupZone,
@PickupDate,
@PickupIntersection,
@DropoffAddress,
@DropoffSuffix,
@DropoffCity,
@DropoffRegion,
@DropoffPostalCode,
@DropoffPhone,
@DropoffZone,
@PaymentMethod,
@CreditCardNumber,
@ExpiryDate,
@InputDate,
@LastActivityDate,
@UserID,
@Passengers,
@WakeupDate,
@ContactName,
@ContactPhone,
@PurchaseOrder,
@Appartment,
@Buzzer,
@UserID,
@Notes,
@psemail,
@email,
@PickupFlight,
@PickupAirline,
@PickupFlightTime,
@DropoffFlight,
@DropoffAirline,
@DropoffFlightTime)
--select @ResID = ResID from Reservations where ReservationID = @MXRSID
SET @ResID = SCOPE_IDENTITY()
INSERT INTO dbo.Dispatches (ResID, VehicleTypeID, Status)
VALUES(@ResID, @VehicleType, 0)
if @@error <> 0
begin
select @varvchrError = 'Error creating the caution. ' + @MXRSID
goto ErrOut
end
commit transaction INS_RES_ID
--@ResID = @ResID output
--exec @MXRSID
-- select @ResID, @MXRSID
Return @ResID
ErrOut:
rollback transaction
raiserror (50099, 16, 1, @varvchrError, 'Insert_Res')
return
I hope you can help, I am in the process of converting my access based
application in to an access data project with SQL Server. I begain doing
this a few years ago and then gave up but I am back at it again. When I
originally started I was using Access 2000 with SQL Server 7. I am now using
Access 2003 and SQL Server 2005. I have a situation where I had something
working in the old versions of access and SQL server but are refusing to
work in the current versions. I have created a stored procedure that inserts
some data in access I have the following code:
Dim rst As New ADODB.Recordset
Dim objCommand As New ADODB.Command
objCommand.ActiveConnection = dbs
'Stored Procedure Name
objCommand.CommandText = "Insert_Res"
objCommand.CommandType = adCmdStoredProc
'objCommand.Parameters.Refresh
objCommand.Parameters("@CustomerID") = Me!CustomerID
// More parameters go here
Set rst = objCommand.Execute
Me.ReservationID = rst(0)
The me.reservationid line cause an error 3265 run time error. My stored
procedure looks like this:
USE [LCS_Master_2003SQL]
GO
/****** Object: StoredProcedure [dbo].[Insert_Res] Script Date: 11/25/2007
13:35:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[Insert_Res]
(
-- Declare all Inputs
-- Reservation Details
----------------------------------------------------------------------------------------
@CustomerID varchar(10),
@FirstName varchar(20),
@LastName varchar(30),
@PickupAddress varchar(30),
@PickupSuffix varchar(4),
@PickupCity varchar(30),
@PickupRegion varchar(2),
@PickupPostalCode varchar(15),
@PickupPhone varchar(15),
@PickupZone varchar(10),
@PickupDate datetime,
@PickupIntersection varchar(100),
@DropoffAddress varchar(30),
@DropoffSuffix varchar(4),
@DropoffCity varchar(30),
@DropoffRegion varchar(2),
@DropoffPostalCode varchar(10),
@DropoffPhone varchar(15),
@DropoffZone int,
@DismissDate datetime = '',
@PaymentMethod varchar(10),
@CreditCardNumber varchar(20),
@ExpiryDate varchar(22),
@InputDate datetime,
@LastActivityDate datetime,
@UserID varchar(30),
@Passengers smallint,
@WakeupDate varchar(22),
@ContactFirstName varchar(50),
@ContactName varchar(30),
@ContactPhone varchar(15),
@contactEmail varchar(50),
@emailc bit,
@PurchaseOrder varchar(15),
@Appartment varchar(5),
@Buzzer varchar(5),
@InitialUserID varchar(30),
@Notes varchar(100),
@psemail varchar(50),
@email bit,
@PickupFlight varchar(50),
@PickupAirline varchar(50),
@PickupFlightTime varchar(50),
@DropoffFlight varchar(50),
@DropoffAirline varchar(50),
@DropoffFlightTime varchar(50),
@Ref as varchar(3),
--This will be used for Dynamic SQL to insert records for Dispatch subtable
--@Disp varchar(2000)
--@MXRSID varchar(10)
@VehicleType int
--@HourlyRate varchar(10),
--@UserID varcahr(30),
--@Hours smallint
-----------------------------------------------------------------------------------------
output
)
As
-- Declare all Variables
Declare
@MXRSID varchar(10),
@MXRSIDPRE INTEGER,
@MXRSINT INTEGER,
@varvchrError varchar(100), -- keeps the error message.
--@ResPre varchar(2),
@VT varchar(10),
@ResID int
--SELECT @ResPre = Reference
--FROM MyCompany
SELECT @MXRSID = MAX(ReservationID)
FROM dbo.Reservations
where ReservationID like @Ref + '%'
if @MXRSID is Null
set @MXRSID = @Ref + '000000'
set @MXRSIDPRE = CAST(SUBSTRING(@MXRSID, 3, 6 ) AS INT)
set @MXRSINT = @MXRSIDPRE + 1
if Len(@MXRSINT) < 6
set @MXRSID = @MXRSINT
if Len(@MXRSINT) = 5
set @MXRSID = @Ref + '0' + CAST(@MXRSINT AS VARCHAR(5))
if Len(@MXRSINT) = 4
set @MXRSID = @Ref + '00' + CAST(@MXRSINT AS VARCHAR(4))
if Len(@MXRSINT) = 3
set @MXRSID = @Ref + '000' + CAST(@MXRSINT AS VARCHAR(3))
if Len(@MXRSINT) = 2
set @MXRSID = @Ref + '0000' + CAST(@MXRSINT AS VARCHAR(2))
if Len(@MXRSINT) = 1
set @MXRSID = @Ref + '00000' + CAST(@MXRSINT AS VARCHAR(1))
if Len(@MXRSINT) = 0
set @MXRSID = @Ref + '000000'
begin transaction INS_RES_ID
INSERT INTO dbo.Reservations
(ReservationID,
CustomerID,
FirstName,
LastName,
PickupAddress,
PickupSuffix,
PickupCity,
PickupRegion,
PickupPostalCode,
PickupPhone,
PickupZone,
PickupDate,
PickupIntersection,
DropoffAddress,
DropoffSuffix,
DropoffCity,
DropoffRegion,
DropoffPostalCode,
DropoffPhone,
DropoffZone,
PaymentMethod,
CreditCardNumber,
ExpiryDate,
InputDate,
LastActivityDate,
UserID,
Passengers,
WakeupDate,
ContactName,
ContactPhone,
PurchaseOrder,
Appartment,
Buzzer,
InitialUserID,
Notes,
Passemail,
email,
PickupFlight,
PickupAirline,
PickupFlightTime,
DropoffFlight,
DropoffAirline,
DropoffFlightTime)
Values(@MXRSID,
@CustomerID,
@FirstName,
@LastName,
@PickupAddress,
@PickupSuffix,
@PickupCity,
@PickupRegion,
@PickupPostalCode,
@PickupPhone,
@PickupZone,
@PickupDate,
@PickupIntersection,
@DropoffAddress,
@DropoffSuffix,
@DropoffCity,
@DropoffRegion,
@DropoffPostalCode,
@DropoffPhone,
@DropoffZone,
@PaymentMethod,
@CreditCardNumber,
@ExpiryDate,
@InputDate,
@LastActivityDate,
@UserID,
@Passengers,
@WakeupDate,
@ContactName,
@ContactPhone,
@PurchaseOrder,
@Appartment,
@Buzzer,
@UserID,
@Notes,
@psemail,
@email,
@PickupFlight,
@PickupAirline,
@PickupFlightTime,
@DropoffFlight,
@DropoffAirline,
@DropoffFlightTime)
--select @ResID = ResID from Reservations where ReservationID = @MXRSID
SET @ResID = SCOPE_IDENTITY()
INSERT INTO dbo.Dispatches (ResID, VehicleTypeID, Status)
VALUES(@ResID, @VehicleType, 0)
if @@error <> 0
begin
select @varvchrError = 'Error creating the caution. ' + @MXRSID
goto ErrOut
end
commit transaction INS_RES_ID
--@ResID = @ResID output
--exec @MXRSID
-- select @ResID, @MXRSID
Return @ResID
ErrOut:
rollback transaction
raiserror (50099, 16, 1, @varvchrError, 'Insert_Res')
return