locked
A query statement doesn't work when wrapped, but worked when one line RRS feed

  • Question

  • User2097951763 posted

    one line,work!

    @{
        var db = Database.Open("Northwind");
        var sql = "SELECT * FROM Categories INNER JOIN Products ON Categories.CategoryID = Products.CategoryID where Products.CategoryID = @0";
    
          
    }
    <table border="1">
    @foreach(var row in db.Query(sql,"1")){
        <tr><td>@row.ProductName</td><td>@row.CategoryName</td><td>@row.Description</td></tr>
    }
    </table>

    wrapped,wrong!

    @{
        var db = Database.Open("Northwind");    
        var sql="seclet ProductName,Description,CategoryName from Categories" + 
                "Inner join Products" + 
                "On Categories.CategoryID = Products.CategoryID" + 
                "where Products.CategoryID = @0";
          
    }
    <table border="1">
    @foreach(var row in db.Query(sql,"1")){
        <tr><td>@row.ProductName</td><td>@row.CategoryName</td><td>@row.Description</td></tr>
    }
    </table>

    Thursday, May 26, 2016 1:59 AM

Answers

  • User325035487 posted

    "seclet ProductName,Description,

    Also wrong spelling for SELECT.. see above

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 26, 2016 5:30 PM

All replies

  • User1287536547 posted

    That is because your concatenating the string with no spaces.

    your looking for this:

    var sql="seclet ProductName,Description,CategoryName from Categories " + 
                "Inner join Products " + 
                "On Categories.CategoryID = Products.CategoryID " + 
                "where Products.CategoryID = @0";

    You need the spaces.

    Hope it helps!

    Thursday, May 26, 2016 3:04 AM
  • User325035487 posted

    "seclet ProductName,Description,

    Also wrong spelling for SELECT.. see above

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 26, 2016 5:30 PM
  • User2097951763 posted

    webMvc

    "seclet ProductName,Description,

    Thank you very much

    Also wrong spelling for SELECT.. see above

    Thursday, May 26, 2016 11:16 PM