locked
Must declare the scalar variable "@0" RRS feed

  • Question

  • User37428675 posted

    I've seen other postings but it was because they were missing parameters..  Either I'm overlooking it or I found a bug in VS 2015..    I downloaded VS 2015 Preview last week and get the error when I do this..

    @{
        var db = Database.Open("db");
        var sqlQuery = "SELECT * FROM [MyDbTest].[dbo].[Table1] WHERE ColID = @0";
        //Must declare the scalar variable "@0" error below
        var result = db.Query(sqlQuery, "43");
    }

    Now, I know I can concatenate the string, but I'm trying to do this the right way.  Anyone see an issue there?

    Monday, December 8, 2014 9:08 AM

Answers

  • User-821857111 posted
    VS 2015 Preview doesn't support Web Pages at the moment. It won't until a few months after ASP.NET 5 RTM.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 9, 2014 12:51 AM

All replies

  • User281315223 posted

    I might be leaning more along the "bug" side of things as the code that you provided should be working (or at least I don't see anything wrong with it). Have you tried using this with a different version of WebMatrix?

    Does it work when you just concatenate the strings or explicitly set your query to use "43" :

    var sqlQuery = "SELECT * FROM [MyDbTest].[dbo].[Table1] WHERE ColID = 43";
    var result = db.Query(sqlQuery);

    Monday, December 8, 2014 9:37 AM
  • User37428675 posted

    Thanks Rion.   Yes it works perfectly when I put the value in string like that.   Just doesn't like me passing it as a parameter.    I'm an old school developer and fairly new to cshtml/razor.  I'm just playing at the moment with the new VS 15.    So this is more of a learning exercise for me on why this isn't working as a parameter.

    Monday, December 8, 2014 9:49 AM
  • User895691971 posted

    As Rion has said, there is no error in the syntax, and the hardcoded string also works. So, then did you try creating a new variable and put that variable in the code? 

    @{
        var db = Database.Open("db");
        var sqlQuery = "SELECT * FROM [MyDbTest].[dbo].[Table1] WHERE ColID = @0";
        var str = "43";
        var result = db.Query(sqlQuery, str);
    }

    What does this yield, error or results?

    Monday, December 8, 2014 10:26 AM
  • User37428675 posted

    Just tried, same error..   I'm going to wrap this up as a bug in VS 15.  

    Currently I'm running 4.5 Framework and tried taking it back to 3.5, which none of the code is supported..  I moved it back up to 4.0 and it compiles, but gives the same error.

    Thanks to you both for your time.

    Monday, December 8, 2014 10:49 AM
  • User281315223 posted

    Just as a follow-up, you may want to consider reporting this issue into Microsoft's Connect portal. This way you can be sure that Microsoft is aware of the issue and can look into a fix in the future (if this is indeed a bug).

    Monday, December 8, 2014 11:12 AM
  • User-821857111 posted
    VS 2015 Preview doesn't support Web Pages at the moment. It won't until a few months after ASP.NET 5 RTM.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 9, 2014 12:51 AM
  • User379720387 posted

    And, they may just declare it deprecated.

    Tuesday, December 9, 2014 1:55 PM
  • User-821857111 posted

    And, they may just declare it deprecated.

    No they won't do that.  I have it from the horses mouth that Web Pages is definitely not going away. It will not be in the RTM of ASP.NET 5 but it will be in the first update following which will be roughly 3-4 months post RTM.

    Tuesday, December 9, 2014 2:39 PM
  • User895691971 posted

    VS 2015 Preview doesn't support Web Pages at the moment. It won't until a few months after ASP.NET 5 RTM.

    And, I have also read that they're making their minds to merge the Web Pages framework into MVC in its 6th version. So that would leave any chance of deprecation too.

    Here is the qoute from the web page on this website: Web Pages will be added to MVC 6 in a later release. http://www.asp.net/vnext/overview/aspnet-vnext/aspnet-5-overview

    Tuesday, December 9, 2014 2:43 PM
  • User37428675 posted

    Ah.. Well that explains it.   I've never used Web Pages, but the demo I was playing with used it.   I've since then move it all over to a class lib using ADO.NET, like it should be anyway.   Thanks for the heads up.

    Wednesday, December 10, 2014 8:26 AM
  • User-1980594115 posted

    Afzaal.Ahmad.Zeeshan thanks for sharing that link.  It was comforting to be reassured that applications that currently use Web Pages 3 will be fully supported on the new ASP.NET 5 framework without modification.  Hence the work we do today with Web Pages will not be deprecated tomorrow.

    Wednesday, December 10, 2014 11:20 AM
  • User895691971 posted

    No it won't be, also to be clear the Razor syntax was really a good feature within the Web Pages, which will be transfered to the MVC model too, Web Pages was just nothing but a simple web site design using cshtml files to embed the server-side code in your HTML pages, where as in the MVC you get a control over the web site in three levels (not to be confused with the databases). Model-View-Controller and so on. Razor will be used as the syntax, and the Web Pages will be merged into the MVC6, you can continue the Web Pages as until now there is no other news but this one news that I have also written in that post. 

    Hopefully Web Pages will be merged, and only MVC 6 will be remaining; Web Forms is a seperate thing, it will be alive as long as it wants to be and updates will come. One thing that I love in this new feature and the updates that the ASP.NET community is giving me, is the JSON syntax. I didn't like the XML structure that much, and now that it is giving me a JSON notation for the properties I am loving it even more. 

    As far as the support is concerned, I am not sure whether you would need a XML to JSON parser to convert the web.config to web.json file too! :D 

    Wednesday, December 10, 2014 1:46 PM