开发者

how to open a database in a webMatrix C# file?

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 开发者_C百科a webMatrix project?


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜