 |
| 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 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
|
|
|

June 16th, 2003, 05:53 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|

June 16th, 2003, 07:20 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|

June 16th, 2003, 07:23 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Correction to above:
http://localhost/gadgetswarehouse/default.aspx?CategoryID="1"
|

June 16th, 2003, 05:36 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
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
|

June 19th, 2003, 05:44 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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)
|

June 19th, 2003, 08:51 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
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
|

June 19th, 2003, 02:56 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 19th, 2003, 07:38 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
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?
|

June 20th, 2003, 09:25 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!!
|

June 20th, 2003, 03:53 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
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?
|
|
 |