If you have created your db in SQL Server Compact as described for example in
Working with data tutorial, building a page that shows the db content it's easy.
Use WebGrid in a page like this:
@{
var db = Database.Open("Materials") ;
var selectQueryString = "SELECT * FROM Parts WHERE Manufacturer = 'MAN'";
var data = db.Query(selectQueryString);
var grid = new WebGrid(data);
}
<!DOCTYPE html>
<html>
<head>
<title>Displaying Data Using the WebGrid Helper</title>
</head>
<body>
<h1>Parts</h1>
<div id="grid">
@grid.GetHtml()
</div>
</body>
</html>
The clause "WHERE Manufacturer = 'MAN'" in the query "SELECT * FROM Parts WHERE Manufacturer = 'MAN'" selects only the rows with MAN as manufacturer.
Could you kindly give me an advice what type of data should be used in the case. I use ntext for Manufacturer.
I have an error. It says that data type ntext and image can't be used with WHERE, HAVING, GROUP BY, ON and IN, if only they aren't mantioned with predicates LIKE or IS NULL.
The nvarchar data type is the one you should use for strings like names or titles. The ntext data type is for larger chunks of text, like descriptions, or article body text.
IvanLykov
Member
6 Points
10 Posts
List of items from DB by for example manufacturer
Mar 03, 2012 11:31 AM|LINK
I have a db "Materials" with table "Parts". Table "Parts" consists of rows: "id, manufacturer, size, color, etc".
What code should I use to build a cshtml page with list of Parts of the one manufacturer?
Sorry 4 my English.
GmGregori
Contributor
5470 Points
737 Posts
Re: List of items from DB by for example manufacturer
Mar 03, 2012 02:04 PM|LINK
If you have created your db in SQL Server Compact as described for example in Working with data tutorial, building a page that shows the db content it's easy.
Use WebGrid in a page like this:
@{ var db = Database.Open("Materials") ; var selectQueryString = "SELECT * FROM Parts WHERE Manufacturer = 'MAN'"; var data = db.Query(selectQueryString); var grid = new WebGrid(data); } <!DOCTYPE html> <html> <head> <title>Displaying Data Using the WebGrid Helper</title> </head> <body> <h1>Parts</h1> <div id="grid"> @grid.GetHtml() </div> </body> </html>The clause "WHERE Manufacturer = 'MAN'" in the query "SELECT * FROM Parts WHERE Manufacturer = 'MAN'" selects only the rows with MAN as manufacturer.
IvanLykov
Member
6 Points
10 Posts
Re: List of items from DB by for example manufacturer
Mar 07, 2012 04:44 PM|LINK
Thank you very much for your answer!
Could you kindly give me an advice what type of data should be used in the case. I use ntext for Manufacturer.
I have an error. It says that data type ntext and image can't be used with WHERE, HAVING, GROUP BY, ON and IN, if only they aren't mantioned with predicates LIKE or IS NULL.
Thank's once more!
Mikesdotnett...
All-Star
154955 Points
19872 Posts
Moderator
MVP
Re: List of items from DB by for example manufacturer
Mar 07, 2012 07:30 PM|LINK
The nvarchar data type is the one you should use for strings like names or titles. The ntext data type is for larger chunks of text, like descriptions, or article body text.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
IvanLykov
Member
6 Points
10 Posts
Re: List of items from DB by for example manufacturer
Mar 09, 2012 08:14 PM|LINK
Mikesdonetting, thanks a lot! You answers realy help.
Best regards, Ivan.