Must declare the scalar variable

前端 未结 8 1281
小蘑菇
小蘑菇 2020-11-29 01:41

@RowFrom int

@RowTo int

are both Global Input Params for the Stored Procedure, and since I am compiling the SQL query inside the St

8条回答
  •  Happy的楠姐
    2020-11-29 02:27

    Just adding what fixed it for me, where misspelling is the suspect as per this MSDN blog...

    When splitting SQL strings over multiple lines, check that that you are comma separating your SQL string from your parameters (and not trying to concatenate them!) and not missing any spaces at the end of each split line. Not rocket science but hope I save someone a headache.

    For example:

    db.TableName.SqlQuery(
        "SELECT Id, Timestamp, User " +
        "FROM dbo.TableName " +
        "WHERE Timestamp >= @from " +
        "AND Timestamp <= @till;" + [USE COMMA NOT CONCATENATE!]
        new SqlParameter("from", from),
        new SqlParameter("till", till)),
        .ToListAsync()
        .Result;
    

提交回复
热议问题