Question

In the webMatrix examples, which I have working, it's very easy to access a database. Only three lines are necessary to get up and going:

@{
    var db = Database.Open("LOS"); 
    var selectQueryString = "SELECT * FROM wknTest";
}

and a little later,

 @foreach(var row in db.Query(selectQueryString)){ 

There's no using's, no connection strings, all that happens behind the scenes. But now I have enough complicated c# code that I want to separate it into a separate C# file. How would I do the above, but in a C# file residing in the app_code folder in a webMatrix project?

Was it helpful?

Solution

From scrounging around, I found I was missing the reference to one of these. I'm not sure if one or both are needed, so I'll not mark the question answered and hopefully someone more knowledgeable than my scrounging will know.

using WebMatrix.WebData;
using WebMatrix.Data;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top