Last post Mar 09, 2012 09:14 PM by IvanLykov
Mar 03, 2012 12:31 PM|IvanLykov|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.
Mar 03, 2012 03:04 PM|GmGregori|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);
<title>Displaying Data Using the WebGrid Helper</title>
The clause "WHERE Manufacturer = 'MAN'" in the query "SELECT * FROM Parts WHERE Manufacturer = 'MAN'" selects only the rows with MAN as manufacturer.
Mar 07, 2012 05:44 PM|IvanLykov|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!
Mar 07, 2012 08:30 PM|Mikesdotnetting|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.
Mar 09, 2012 09:14 PM|IvanLykov|LINK
Mikesdonetting, thanks a lot! You answers realy help.
Best regards, Ivan.