Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Wrox Announcements and Feedback > All Other Wrox Books
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
All Other Wrox Books Do you have a question about a Wrox book that isn't listed anywhere on p2p.wrox.com or where the forum is locked? Here's a forum to post questions about any other Wrox book so that other readers or one of the authors can help you with your questions. IF YOU ARE LOOKING FOR CODE DO NOT ASK "Where can I find the code for this book?" That question is answered here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the All Other Wrox Books section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 16th, 2003, 05:53 AM
Authorized User
 
Join Date: Jun 2003
Location: Stockholm, , Sweden.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP.NET E-Commerce Prog Problem - Design -

I have recently bought this book!

When running http://localhost/gadgetswarehouse/default.aspx in my browser I’m getting:

"Must declare the variable '@CategoryID'."

Something must be wrong with the way the parameters are passed in the calls. Access to the database seems to be OK - but I'm stumbling when trying to execute the stored procedure!

How do I fix this problem?
  #2 (permalink)  
Old June 16th, 2003, 07:20 AM
Authorized User
 
Join Date: Jun 2003
Location: Stockholm, , Sweden.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have also tried to add a parameter i.e.
http://localhost/gadgetswarehouse/default.aspx?Category="1"

the result is:
Input string was not in a correct format.

How do I fix the problem?
  #3 (permalink)  
Old June 16th, 2003, 07:23 AM
Authorized User
 
Join Date: Jun 2003
Location: Stockholm, , Sweden.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Correction to above:
 http://localhost/gadgetswarehouse/default.aspx?CategoryID="1"
  #4 (permalink)  
Old June 16th, 2003, 05:36 PM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

It sounds to me like the problem is with the Stored Procedure.. Check the SP and make sure you spelled the Parameter name correctly.


Hal Levy
Daddyshome, LLC
  #5 (permalink)  
Old June 19th, 2003, 05:44 AM
Authorized User
 
Join Date: Jun 2003
Location: Stockholm, , Sweden.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Hal,

I belive it's something more fundamental than a simple spelling problem!
Please have a look at the following listing:

Server Error in '/gadgetswarehouse' Application.
--------------------------------------------------------------------------------

Must declare the variable '@CategoryID'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the variable '@CategoryID'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SqlException: Must declare the variable '@CategoryID'.]
   System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +643
   System.Data.SqlClient.SqlCommand.System.Data.IDbCo mmand.ExecuteReader(CommandBehavior behavior) +9
   System.Data.Common.DbDataAdapter.Fill(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +38
   GW.CMPServices.SqlPersistenceContainer.AssignRetur nValueToDataSet(CommandMapping cmdMap, SqlCommand currentCmd, PersistableObject& persistObjectSet)
   GW.CMPServices.SqlPersistenceContainer.Select(Pers istableObject selectObject)

[Exception: Persistance (Select) Failed for PersistableObject]
   GW.CMPServices.SqlPersistenceContainer.Select(Pers istableObject selectObject)
   GW.Web.ProductCatalog.ProductCatalog.GetChildCateg ories(Int32 categoryId)
   GW.Web.ProductCatalog.ProductCatalog.GetCategories ()
   GW.Web.UserControls.TopCategoryDropDown.BindData()
   GW.Web.UserControls.TopCategoryDropDown.Page_Load( Object sender, EventArgs e)
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +29
   System.Web.UI.Control.LoadRecursive() +92
   System.Web.UI.Control.LoadRecursive() +92
   System.Web.UI.Page.ProcessRequestMain() +707




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.0.3705.0; ASP.NET Version:1.0.3705.0
Request Details
Session Id: Request Type: GET
Time of Request: 6/19/2003 12:26:05 PM Status Code: 500
Request Encoding: Unicode (UTF-8) Response Encoding: Unicode (UTF-8)
Trace Information
Category Message From First(s) From Last(s)
aspx.page Begin Init
aspx.page End Init 0.009323 0.009323
 Entering SqlPersistenceContainer.Select() [Signature: Void Select(GW.CMPServices.PersistableObject)] 0.020022 0.010699
 Executing Stored Proc: Gw_Select_Categories 0.021128 0.001106
 Command Parameter Added for SQL Persistence: @CategoryId 0.021267 0.000139
 param direction : Input 0.021406 0.000139
 Value Set for Parameter @CategoryId is -1 0.021566 0.000160
 Selecting Plural 0.052487 0.030922
Unhandled Execution Error

Persistance (Select) Failed for PersistableObject
  at GW.CMPServices.SqlPersistenceContainer.Select(Pers istableObject selectObject)
  at GW.Web.ProductCatalog.ProductCatalog.GetChildCateg ories(Int32 categoryId)
  at GW.Web.ProductCatalog.ProductCatalog.GetCategories ()
  at GW.Web.UserControls.TopCategoryDropDown.BindData()
  at GW.Web.UserControls.TopCategoryDropDown.Page_Load( Object sender, EventArgs e)
  at System.Web.UI.Control.OnLoad(EventArgs e)
  at System.Web.UI.Control.LoadRecursive()
  at System.Web.UI.Control.LoadRecursive()
  at System.Web.UI.Control.LoadRecursive()
  at System.Web.UI.Page.ProcessRequestMain() 0.070975 0.018488

Control Tree
Control Id Type Render Size Bytes (including children) Viewstate Size Bytes (excluding children)
Headers Collection
Name Value
Connection Keep-Alive
Accept */*
Accept-Encoding gzip, deflate
Accept-Language sv
Host localhost
User-Agent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
Server Variables
Name Value
ALL_HTTP HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:*/* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:sv HTTP_HOST:localhost HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
ALL_RAW Connection: Keep-Alive Accept: */* Accept-Encoding: gzip, deflate Accept-Language: sv Host: localhost User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
APPL_MD_PATH /LM/W3SVC/1/Root/gadgetswarehouse
APPL_PHYSICAL_PATH C:\Inetpub\wwwroot\GWSetup\
AUTH_TYPE
AUTH_USER
AUTH_PASSWORD
LOGON_USER
REMOTE_USER
CERT_COOKIE
CERT_FLAGS
CERT_ISSUER
CERT_KEYSIZE
CERT_SECRETKEYSIZE
CERT_SERIALNUMBER
CERT_SERVER_ISSUER
CERT_SERVER_SUBJECT
CERT_SUBJECT
CONTENT_LENGTH 0
CONTENT_TYPE
GATEWAY_INTERFACE CGI/1.1
HTTPS off
HTTPS_KEYSIZE
HTTPS_SECRETKEYSIZE
HTTPS_SERVER_ISSUER
HTTPS_SERVER_SUBJECT
INSTANCE_ID 1
INSTANCE_META_PATH /LM/W3SVC/1
LOCAL_ADDR 127.0.0.1
PATH_INFO /gadgetswarehouse/default.aspx
PATH_TRANSLATED C:\Inetpub\wwwroot\GWSetup\default.aspx
QUERY_STRING
REMOTE_ADDR 127.0.0.1
REMOTE_HOST 127.0.0.1
REQUEST_METHOD GET
SCRIPT_NAME /gadgetswarehouse/default.aspx
SERVER_NAME localhost
SERVER_PORT 80
SERVER_PORT_SECURE 0
SERVER_PROTOCOL HTTP/1.1
SERVER_SOFTWARE Microsoft-IIS/5.1
URL /gadgetswarehouse/default.aspx
HTTP_CONNECTION Keep-Alive
HTTP_ACCEPT */*
HTTP_ACCEPT_ENCODING gzip, deflate
HTTP_ACCEPT_LANGUAGE sv
HTTP_HOST localhost
HTTP_USER_AGENT Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
  #6 (permalink)  
Old June 19th, 2003, 08:51 AM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Your trying to persist the data to the database...
Quote:
quote:
Version Information: Microsoft .NET Framework Version:1.0.3705.0; ASP.NET Version:1.0.3705.0
Request Details
Session Id: Request Type: GET
Time of Request: 6/19/2003 12:26:05 PM Status Code: 500
Request Encoding: Unicode (UTF-8) Response Encoding: Unicode (UTF-8)
Trace Information
Category Message From First(s) From Last(s)
aspx.page Begin Init
aspx.page End Init 0.009323 0.009323
Entering SqlPersistenceContainer.Select() [Signature: Void Select(GW.CMPServices.PersistableObject)] 0.020022 0.010699
Executing Stored Proc: Gw_Select_Categories 0.021128 0.001106
Command Parameter Added for SQL Persistence: @CategoryId 0.021267 0.000139
param direction : Input 0.021406 0.000139
Value Set for Parameter @CategoryId is -1 0.021566 0.000160
Selecting Plural 0.052487 0.030922
Unhandled Execution Error
As you can see here- the Parameter @CategoryID is set. Again, I am wondering about the Stored Procedure that is used to persist the data into the database- Can you paste it here?

Hal Levy
Daddyshome, LLC
NOT a Wiley/Wrox Employee
  #7 (permalink)  
Old June 19th, 2003, 02:56 PM
Authorized User
 
Join Date: Jun 2003
Location: Stockholm, , Sweden.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is a paste of the procedure:

CREATE PROCEDURE Gw_Select_Categories
@CategoryId int
AS
    IF @CategoryID = -1
        SELECT CategoryId, Description, Notes, ParentCategoryId FROM Categories Order by Description
    ELSE
        SELECT CategoryId, Description, Notes, ParentCategoryId FROM Categories WHERE ParentCategoryId = @CategoryId ORDER BY Description
GO
  #8 (permalink)  
Old June 19th, 2003, 07:38 PM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Change it to this and let me know what happens:

Code:
CREATE PROCEDURE Gw_Select_Categories
@CategoryId int = -1
AS
    IF @CategoryId = -1
        SELECT CategoryId, Description, Notes, ParentCategoryId FROM Categories 
          Order by Description
    ELSE
        SELECT CategoryId, Description, Notes, ParentCategoryId FROM Categories
          WHERE ParentCategoryId = @CategoryId
          ORDER BY Description
GO
Hal Levy
NOT a Wiley/Wrox Employee- Got a job for me?
  #9 (permalink)  
Old June 20th, 2003, 09:25 AM
Authorized User
 
Join Date: Jun 2003
Location: Stockholm, , Sweden.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just made the following change in the Store Procedure 'Gw_Select_Categories':

IF @CategoryID = -1 ---->> IF @CategoryId = -1

this solved my problem!


Thanks a million Hal!!!
  #10 (permalink)  
Old June 20th, 2003, 03:53 PM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

No Problem.. I noticed the case problem but I never bothered to test case sensitivity in SQL Server- so I didn't suggest it. Now I know

Hal Levy
NOT a Wiley/Wrox Employee- Got a job for me?
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET E-Commerce Programming Problem-Design-Solu kenzhen All Other Wrox Books 1 April 27th, 2005 06:50 AM
ASP.NET E-Commerce Program Problem-Design-Solution ruimeisoft All Other Wrox Books 6 August 17th, 2004 03:10 AM
ASP.NET E-commerce Programming: Problem - Design - rmccue Wrox Book Feedback 1 February 9th, 2004 09:30 AM
ASP.NET E-Commerce Prog Problem - Design -Solution cat2123 All Other Wrox Books 1 December 29th, 2003 06:27 AM
ASP.NET E-Commerce Programming Problem - Design - nodoubt223rd All Other Wrox Books 8 June 30th, 2003 09:29 PM



All times are GMT -4. The time now is 04:44 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.