2

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?

Gavin5511
  • 791
  • 5
  • 31

1 Answers1

3

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
} 
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • just to confirm, if i wanted to run another query on the page, i could do the same using the @1 value? does it make a difference what order they are in? – Gavin5511 Mar 02 '13 at 11:15
  • You could use as many parameters as you like in a single query. They should be numbered @0, @1, @2, ... and the values passed in the same order to the `Query` method. – Darin Dimitrov Mar 02 '13 at 13:09