Jeep
Jeep

Reputation: 1

How do I run a Dynamic SQL Query in Webmatrix?

I'm working on something in WebMatrix that runs an SQL Query. I can do that, however, it Selects * From UserProfile WHERE Email = @WebSecurity.CurrentUserName. I have no idea how to get it to read only a column where Email = @WebSecurity.CurrentUserName. I listed my code below.

@{
var db=Database.Open("AeroSC");
var sqlQ = "SELECT * FROM UserProfile";
var data = db.Query(sqlQ);
}

How do I go about doing this?

Thanks!

Upvotes: 0

Views: 1230

Answers (1)

Mike Brind
Mike Brind

Reputation: 30110

@{
    var db = Database.Open("AeroSC");
    var sqlQ = "SELECT Id FROM UserProfile WHERE Email = @0";
    var id = db.QueryValue(sqlQ, WebSecurity.CurrentUserName);
}

Upvotes: 1

Related Questions