3

I followed the following tutorial to help me create a datagrid (http://www.asp.net/web-pages/videos/aspnet-razor-pages/displaying-data-in-a-grid), however, I keep getting the error in the title under the word database. I've tried replacing it with the name of my database (Products) however that didnt work. Does anyone know why it could be happening? This piece of code sits at the top of my view page:

@{

   var _db = database.open("Products");

   var selectQueryString = "SELECT * FROM Products ORDER BY DateBought, SortOrder";

   var data = _db.query(selectQueryString);

   var grid = new WebGrid(Model);

}

When I check the values I receive in the drop down menu when I type var _db = datab.. I only have the following available:

Databinding, Databinder, DatabindingCollection, Databindinghandlerattribute, databindingliteralcontrol, Designerdataboundliteralcontrol, Idatabindingsassessor

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Blob
  • 541
  • 3
  • 20
  • 38

2 Answers2

0

I had the same error and I found this solution that worked for me: http://www.w3schools.com/aspnet/webpages_database.asp

It seems that Webmatrix2 doesn't include the said .dll by default. I only had to download the nuget package from Webmatrix's gallery and it worked.

I hope it helps others.

Verbeia
  • 4,400
  • 2
  • 23
  • 44
Cranca
  • 1
0

You need to add a Reference to WebMatrix.Data.dll

Database class is part of WebMatrix.Data there for is only available through that dll.

You can find WebMatrix.Data.dll in [Program Files Directory]\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies or v2.0\Assemblies regarding the version you have installed.

djsolid
  • 385
  • 2
  • 10