Quantcast

Creating Database Display with Razor

With Razor, you can easily display data from a database in your web pages. You can create a database using programming code, but it is more typical (and easier) to use a design tool. An example of the Razor code for a simple table is as follows:

The output of this code would be a simple table listing all the products, their descriptions and respective prices. A designing tool available for database creation is SQL Server Compact Database design tool which is included in the WebMatrix. To develop simple database named MyDatabase using this tool, you need to follow these instructions:

Create a new web site and call the site “MyDatabase”. Create a new database which would be done using the WebMatrix. The name of this database would be MyDatabase.sdf. Now create a new table in the database by opening the MyDatabase.sdf and clicking New Table. The table designer would be opened by the WebMatrix. Having done this, create a new column named ‘ID’ and set the ‘Is Identity’ and ‘Is Primary Key’ to true. Is Primary Key tells the database that this will be the table’s primary key. Is Identity tells the database to automatically create an ID number for every new record and to assign it the next sequential number (starting at 1).

Similarly, create columns for Name, Description and Price. Having done that, save the table and name it ‘Product.’ After that, adding data to the table is a trivial task. With this simple method, users can create their personal database to handle the transactions and other requirements in a limited time.

Looking for a quality hosting service? here are a few I suggest.
BlueHost | HostGator | Media Temple
Admin
Admin
Ali has been an entrepreneur in web, video and related technologies. Having worked with many business across the globe, Ali stands truly a great pillar in the business working with him.