Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C# shopping basket, trying to remove an item...

1235

Comments

  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I think I've a small problem with one stored proc... I had one in your previous solution called usp_select_ProductSpec and I renamed that to usp_select_AllProductsBySpec...

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[usp_select_AllProductsBySpec]
    (
    @SpecID INT
    )
    AS
    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID
    WHERE SpecProduct.SpecID = @SpecID


    Does this look good? After I changed the SP name to usp_select_AllProductsBySpec, the solution would compile but when I use the Dropdown list, I don't get any items in the catalog, it could just be that I haven't populated the DB properly to work with the script but before I go looking at that, I just want to see if my stored proc is good...


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Looks fine..

    Just run the following query on the database

    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID

    and see if it returns any rows.

    You will see then what products are matched to what specs and then that will allow you to select what dropdowns will show info

    If you look in the script you will see I prepopulated the table so you can see some info


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    i was going to try to populate the DB using the script you used but I don't have the AdventureWorks DB on my server so I couldn't copy the records over... I'm just installing it locally now...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I've noticed when I try to add more than one specialisation for a SubCat, by going into the spec table and changing the SubCatID value for two records to have the same SubCatID value, that when I compile, the value is there on the specialisation dropdown layer but if there are 2 options in the list and I try to select the second one, after I release the mouse, it just jumps back to the first option on the specialisation layer...

    1 Spec 1A1 1
    2 Spec 1A2 1
    3 Spec 1A3 2
    4 Spec 1B1 2
    5 Spec 4A1 3
    6 Spec 5A1 4
    7 Spec 5A2 5
    8 Spec 6A1 6

    Just wondering can I do this or have I made a mistake in what I'm doing? :confused::confused::confused:


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    In the one I have it works fine, I just changed it now so that the first 2 specs have a subcatid of 1 and they work fine.

    Did you use my particular code or your own?

    Also the data for all the products is in the script, so you dont required the adventureworks database


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Looks fine..

    Just run the following query on the database

    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID

    and see if it returns any rows.

    You will see then what products are matched to what specs and then that will allow you to select what dropdowns will show info

    If you look in the script you will see I prepopulated the table so you can see some info

    When I run that SQL script I get back 4 rows but they aren't showing up in my aspx page. Also when I try to allow two options for the bottom serialisation layer, I get two options in the list but like before when I take the cursor off the list, the bottom item selected jumps back to the first option on the bottom/3rd drop down list...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I found the problem or the have sort of found it...

    In one of my stored procs:

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[usp_select_AllProductsBySpec]
    (
    @SpecID INT
    )
    AS
    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID
    WHERE SpecProduct.SpecID = @SpecID

    The table is was called specProduct but the SP above referred to SpecProduct. This last line in the SP seems to be the problem...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Here's where I've the problem...

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[usp_select_AllProductsBySpec]
    (
    @SpecID INT
    )
    AS
    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID
    WHERE SpecProduct.SpecID = @SpecID

    When I replace @SpecID above with a number, as in 1, 2 or 3 or whatever, I get the product with that ID. But when I just put in @SpecID, I don't get anything although I should get records back because my Spec table and my Product table have records with 1 as ID... :confused::confused::confused:

    I checked the ProductBl.cs file and the SpecID is referred to there with a small case specID, I was thinking that could be the problem but when I changed it, no difference...


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    When you run the page, view the source of it and see what values are being applied to the dropdown Specialisation. If all the value are 0, its a problem in the stored proc to get all the specialisations


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    If your stored proc is the same as the one you previously posted ie

    ALTER PROCEDURE [dbo].[usp_select_spec]
    (
    @CatID INT
    )
    AS
    SELECT ID,[Name] FROM Spec WHERE SubCatID = @CatID


    Change ID to Id and it will work


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    You'd think I've have remembered that!!!!! :D:D:D


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I don't know whether to laugh or cry!!! It's finally working...

    But when I upload it to my Web Server, I get the same error I had a week or two ago when I was still using MSVDE 2005...

    Server Error in '/' Application.
    Configuration Error
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

    Source Error:

    Line 25: <add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    Line 26: <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
    Line 27: <authentication mode="Windows"/>
    Line 28: <pages>
    Line 29: <controls>




    Last week I called my hosting company and asked them was my package 3.5 .net enabled and he said it was... Although when I log into my Admin panel, there are only two options, asp version 1 or 2... This is working grand on my local dev server so I'm assuming the fact that I can't run the solution on my web server is down to a hosting issue???


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    have you more than one site that is using .net on this package? Sounds like you have a top sit created a new folder below it and popped this new solution in that folder. Its this second web.config is causing the problem as its not allowed


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    have you more than one site that is using .net on this package? Sounds like you have a top sit created a new folder below it and popped this new solution in that folder. Its this second web.config is causing the problem as its not allowed

    Yeah I've a few sites on the same package and they are running asp.net. I'll get onto the hosting co in the morning and see what they say. I always assumed each site was independent of other sites on the same hosting package...


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    they are provided you have them in seperate folders. If you have this solution in a sub folder of an existing asp.net site you will get this error


  • Advertisement
  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    they are provided you have them in seperate folders. If you have this solution in a sub folder of an existing asp.net site you will get this error

    I just had a think about this... I've a few other sites running on this hosting package but they all have their own web.config file and they've all been working away grand before I tried to upload this solution. I think I uploaded it wrong, because this approach of uploading a solution with different projects and folders is new to me. Previously I just uploaded a load of files that sat in the wwwroot folder and all worked fine.

    After I upload the solution, I should refer to the Catalog.aspx file as www.mydomain.ie/ShoppingCartDemo/Catalog.aspx? The way I've done this up until now has been just upload the files and then view it by vieiwing www.mydomain.ie/Default.aspx or whatever the name of the page may be... Just wondering is there any rules I need to be aware of when uploading a solution like this with different projects and subfolders???


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    What I mean to ask is if I uploaded this correctly, should I be using the URL www.mydomain.ie/Catalog.aspx or should I be using the URL www.mydomain.ie/ShoppingCartDemo/Catalog.aspx???


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    First 1

    You shouldnt have the shoppingcartdemo in the name at all

    The problem is where the folder is sitting etc.

    Its basically an issue of how you publish it


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I see what you mean, I sorted that out so now I don't have the ShoppingCartDemo sub directory there. I got onto my hosting co as they reckon they have to make some changes to my hosting package to get this working, something to do with trust level settings...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Security Exception
    Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

    Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.

    Source Error:

    [No relevant source lines]


    Source File: App_Web_wdiltxyx.2.cs Line: 0

    Stack Trace:

    [SecurityException: That assembly does not allow partially trusted callers.]
    ASP.catalog_aspx..ctor() in App_Web_wdiltxyx.2.cs:0
    __ASP.FastObjectFactory_app_web_wdiltxyx.Create_ASP_catalog_aspx() in App_Web_wdiltxyx.7.cs:0
    System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
    System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +119
    System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
    System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
    System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +160
    System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

    Just wondering could I change the trust level in my config.web file to resolve this?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Make sure all the assemblies are strongly named.

    If you downloaded a version of my projects other the first one, it would have asked for a password when you ran it first.

    Check the project properties of each project and verify that they are being signed


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Also possible you could add

    <trust level="Full"> in the system.web part of your web.config


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I tried the <trust level="Full"> and I get this:

    Configuration Error
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: This configuration section cannot be used at this path. This happens when the site administrator has locked access to this section using <location allowOverride="false"> from an inherited configuration file.

    Source Error:

    Line 15:
    Line 16: <customErrors mode="Off"/>
    Line 17: <trust level="Full" />
    Line 18: <compilation debug="true">
    Line 19: <assemblies>


    When I got this I got onto my hosting co and they said they need to do a bit of rummaging around with my hosting package to get it working...


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Take it out for the moment.

    Verify that your virtual directories are not on networked drives as they may be causing an issue


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Take it out for the moment.

    Verify that your virtual directories are not on networked drives as they may be causing an issue

    It just goes back to the previous error when I take <trust level="Full"> out of the config file...

    Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers, blah blah blah...


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Understandable but it sounds like a config error somewhere on the host but I cant say much more than that...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Understandable but it sounds like a config error somewhere on the host but I cant say much more than that...

    Just off the phone to the hosting co again, they are certain now that it's an issue with the site configuration at their end. They'll have it sorted in a few minutes hopefully. They have Trust levels set that I can't override through the config file so they have to kind of change privileges for my site so I can set trust levels for my own site...


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Cool..

    Hopefully this will all work in the end


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Cool..

    Hopefully this will all work in the end

    Happy days, its working now!


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    RIght then .. interesting project.. hope you learned some stuff from it..

    Best of luck in the rest of it


  • Advertisement
  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    RIght then .. interesting project.. hope you learned some stuff from it..

    Best of luck in the rest of it

    I want to get on top of this "Data Access Layer" and "Business Logic Layer", use methods and that stuff... It's starting to make sense, now that it works and runs remotely I can fiddle around with it and see how the different layers interact with each other... Thanks so much for your help and patience with it!


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Just an FYI updated the version of this with a blog post etc..


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I tried today to change the data type of the Cost from int to float and did the following:

    (1) I changed the column type in the DB

    (2) I made a change in the Product.cs file to change declare Cost as a float intead of an int.

    (3) I made a change in the CartItem.cs file to change TotalPrice from an int to a float.

    (4) In the Catalog.aspx.cs file I changed _totalprice from an int to a float.

    I've rummaged around within the solution for any other declaration of variables that I thought could be causing the attached error but I can't find any... :confused::confused::confused:

    I'm just checking out your blog here...


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Change it to double in both database and code..


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Change it to double in both database and code..

    I just tried to do it in my DB but "double" isn't an option when I try to modify the column... The only two data types starting with d are "decimal" and "datatype"...


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Oki doki

    Just had a quick look at http://msdn.microsoft.com/en-us/library/ms131092.aspx

    SQL float == .NET double

    so change the code to double and it shoudl be fine.. leave the database at float


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    If that doesnt work, I will have to work out some form of conversion


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Oki doki

    Just had a quick look at http://msdn.microsoft.com/en-us/library/ms131092.aspx

    SQL float == .NET double

    so change the code to double and it shoudl be fine.. leave the database at float

    That sorted it out Ginger, thanks agan...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I'm fiddling around with this at the minute and am trying to add a bit onto the solution by uploading an image into my Product DB table and then getting the thumbnail image to display in my Catalog with the other variables, I'm just trying to get an image to show up on the catalog for any given DB record that might be returned based on a dropdown selection, and then if the thumbnail is clicked, I want a larger sized image to be returned.

    What I'd like to have is for a thumbnail image to come up automatically in the Catalog and then if this thumbnail is clicked, a full sized image to appear.

    I've added two new variables of type bool and varchar named Image_Data and Image_Name respectively to the Product.cs file in Entities and I've also ammended my DB to have two new columns for my image data and image name...

    After that, is it just a matter of setting up a ImageButton in my aspx page???

    Like this:

    <td><asp:LinkButton ID="_ViewImage" CommandArgument="<%# ((Product)Container.DataItem).Image_Name %>" CommandName="ViewImage" runat="server" Text="Image" /> </td>


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Sorry mate was meant to come back to this

    It doesnt need to be that complex..

    You can use a simple <a href="ViewLargeImage.aspx?=<%# ((Product)Container.DataItem).Image_Id %>"><img src="image"></a>

    You should use a bool, and an id, and path to the image (or if you are storing the image in the database, use a bytes[] )


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Thanks a mil for that... What I'm also trying to do is use different product tables in my DB to product different dropdown lists depending on what page a user is on. Say they are on a page on the site for car engines, then the dropdown lists (_Make, _Model, _EngineType) and the parts available for that particular product are populated from the CarEngine table in my DB. If the user moves onto another page say Clutches, then the dropdown lists and parts associated with that product are populated from the Clutch Table.

    Before I go into this, is this actually possible??? I'm hoping its just a matter of copying the code so far and creating a new method, some new variables and stored procedures, for each new product table. I just wanted to check with you that it was reasonably possible with the solution before I jumped into it???

    Another way of doing the above would be to add a fourth dropdown list to deal with this but I'd like to go at it the first way if it was handy enough...


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Actually its a bit easier than that :)

    Create a new table called say Type and create it with an Id field int auto incrementing and a Name field which is varchar(50) and primary key the id field.

    Add a few rows say clutches, exhausts whatever

    Now add a new field to Product called TypeID and make it an int...

    You can then assign a typeid to each product

    Now all you need to do is change the GetAllProducts in both Business and Data to accept an int and change the storedprocs for those functions to accept an int and select based on typeid (you dont need to return it)

    What happens now, is you select your products by typeid so that you only get back the set that matches for example clutches.. No changes required for the subcat and spec dropdowns at all


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Sorry mate was meant to come back to this

    It doesnt need to be that complex..

    You can use a simple <a href="ViewLargeImage.aspx?=<%# ((Product)Container.DataItem).Image_Id %>"><img src="image"></a>

    You should use a bool, and an id, and path to the image (or if you are storing the image in the database, use a bytes[] )

    I'm getting an unexpected error on this... I added just one line of code to my Default.aspx page,

    <td><%# ((Product)Container.DataItem).Description %></td>
    <td>€<%#((Product)Container.DataItem).Cost.ToString(CultureInfo.InvariantCulture) %></td>
    <td><%# ((Product)Container.DataItem).Image_Name %> </td>

    I added one line to the Product.cs file under Common/Entities:

    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public double Cost { get; set; }
    public string Image_Name { get; set; }

    And I'm getting an error:

    Compiler Error Message: CS1061: 'ShoppingCart.Common.Entities.Product' does not contain a definition for 'Image_Name' and no extension method 'Image_Name' accepting a first argument of type 'ShoppingCart.Common.Entities.Product' could be found (are you missing a using directive or an assembly reference?)

    in relation to the code at:
    <td><%# ((Product)Container.DataItem).Image_Name %> </td>

    The weird thing is I added a variable last week into the same two pages and I didn't get this compilation error... This has me confused, I haven't really tried to do anything other than add a variable and it won't even compile now???


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Build common project first


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Build common project first

    No luck... It'll compile locally but not when I upload it to the web server.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Sounds like the latest assemblies arent being uploaded...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    That's what's happening, it's like as if when I upload the file to the webserver, it isn't being changed.

    I tried changing the variable name locally by one character so in my Product.cs file it's called _Image1 and in my Default.aspx file I've left it at _Image and then when I try to compile, I get the same error that I'm getting when I try to load the page on the remote webserver.

    I'm just going to try uploading the whole solution again.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Uploading the whole solution again seems to have resolved the issue. Weird! It's going to be a long day trying to get this working and having to upload the whole solution every time I want to add a variable! ;-)


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Actually what needs to upload is the files in the bin directory... otherwise those assemblies dont get updated..

    Because you are using a multiple project solution, you will see in the bin directory in your web application there is a couple of dlls and these must be uploaded when you change anything in the underlying sttructure. So if you make a change in common, you need to upload the new common.dll file..


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    That's great to know that. I wasn't uploading that file yesterday so that must have been the problem.


  • Advertisement
Advertisement