문제

I am trying to write a query to show all records owned by the current logged on user but i am having issues inserting the "userid" variable into the string?

@{
Layout = "~/_template1.cshtml";
var db = Database.Open("StayInFlorida");


var userid = WebSecurity.CurrentUserId;
var premierproperty = "SELECT PropertyName, PropertyID FROM PropertyInfo WHERE OwnerID='userid'";
}

<h1>Properties - Page coming soon</h1>

@userid

@foreach (var row in db.Query(premierproperty)){
@row.propertyname
} 

Any ideas?

도움이 되었습니까?

해결책

Try like this:

@{
    Layout = "~/_template1.cshtml";
    var db = Database.Open("StayInFlorida");
    var userid = WebSecurity.CurrentUserId;
    var premierproperty = "SELECT PropertyName, PropertyID FROM PropertyInfo WHERE OwnerID = @0";
}

<h1>Properties - Page coming soon</h1>

@userid

@foreach (var row in db.Query(premierproperty, userid))
{
    @row.propertyname
} 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top