Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2004, 05:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stored Procedure Default Value

    Hello, I read that when using stored procedures you can set a default value as shown below, so that if nothing gets passed in the parameter the value will default to the given value. When I try this I get the following error. Did I misread this not understand this correctly? (I have tested these samples one at a time to make sure I was doing this correctly and received the same error results for both.)

@strDM_QuoteDueDate datetime = NULL,
@strDM_BindShippableBoxes bit = 1,

ADODB.Command error '800a0d5d'
Application uses a value of the wrong type for the current operation.


Thanks
Mike
__________________
Peace
Mike
http://www.eclecticpixel.com
 
Old November 23rd, 2004, 07:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can you post just the CREATE PROCEDURE statement along with the parameter definition and also about how you are trying to execute the procedure?

Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old November 24th, 2004, 10:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help! This is the code from my asp page. The reason I am asking if this is possible is that the Shippable Boxes is a checkbox and if it is not checked then a value will not be passed, and the database errors out. So my thinking is that if I can supply the default value as shown below it would prevent this, and that when the user does select the checkbox it will overide the default value at the database. Am I correct on this thought?

Set objCmd = Server.CreateObject("ADODB.Command")
With objCmd
.ActiveConnection = strConnect
.CommandText = "sp_ModifyBid"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@strID", adInteger, adParamInput, , strPieceID)
.Parameters.Append .CreateParameter("@strDM_QuoteDueDate", adDate, adParamInput, , strEstimateDue)
.Parameters.Append .CreateParameter("@strDM_BindShippableBoxes", adInteger, adParamInput, , strBindShippableBoxes)
.Execute
End With


CREATE PROCEDURE sp_ModifyBid
(
@strID int,
@strDM_QuoteDueDate datetime = NULL,
@strDM_BindShippableBoxes bit = 0
)
AS
BEGIN TRAN
If @strID > 0
BEGIN
    UPDATE DirectMail
    SET
    DM_QuoteDueDate = @strDM_QuoteDueDate,
    DM_BindShippableBoxes = @strDM_BindShippableBoxes
    WHERE ID_DM = @strID
END
Else
BEGIN
    INSERT INTO DirectMail
    (DM_QuoteDueDate, DM_BindShippableBoxes)
    VALUES
    (@strDM_QuoteDueDate, @strDM_BindShippableBoxes)
END
IF @@ERROR <> 0
    ROLLBACK TRAN
ELSE
    COMMIT TRAN

Thanks
Mike
 
Old November 24th, 2004, 11:54 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

You have to add validation in your ASP page based on the selection for @strDM_BindShippableBoxes.

If there is some value then only pass this parameter in the SP. Otherwise you can leave this parameter as it already have the default value of 0.


Om Prakash
 
Old November 24th, 2004, 01:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Are you aware that you are using @strDM_BindShippableBoxes as BIT type in the SP and passing the parameter as adInteger in your ASP code? Use the correct type in both the places. Then something like this should work for you.
Code:
Set objCmd = Server.CreateObject("ADODB.Command")
With objCmd
.ActiveConnection = strConnect
.CommandText = "sp_ModifyBid"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@strID", adInteger, adParamInput, , strPieceID)
If len(trim(strEstimateDue))>0 then 
    .Parameters.Append .CreateParameter("@strDM_QuoteDueDate", adDate, adParamInput, , strEstimateDue)
End If
If len(trim(strBindShippableBoxes))>0 then
    .Parameters.Append .CreateParameter("@strDM_BindShippableBoxes", adInteger, adParamInput, , strBindShippableBoxes)
End If
.Execute
End With
Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old November 24th, 2004, 03:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks I will fix the bit type.

Just so you know this actually has about 50 fields , I added the validation like you all have told me. What is happening is that the number of parameters being passed does not match the SP parameters. So it is ignoring the @strDM_BindShippableBoxes bit = 0 and moving everything below it up one and erroring out telling me the parameters do not match up.

Passing Par 1int = SP Para 1 int
Passing Par 3 int = SP Para 2 datetime
                                 =SP Para 3 int
 
Old November 24th, 2004, 07:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Mike,

You should actually append all parameters to the Command object, but assign value only if the variable contains something. That was just the logic of code. You got to alter that accordingly.

Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure muthu555 SQL Server 2000 1 March 5th, 2007 07:13 AM
Help About Stored Procedure zhuge6 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 May 20th, 2005 09:27 AM
stored procedure allang MySQL 3 January 26th, 2005 12:48 PM
Stored Procedure desireemm SQL Language 5 September 18th, 2004 02:34 AM
C# and stored procedure Msmsn C# 1 August 26th, 2003 11:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.