Summary
WebMatrix is indeed very helpful for rapid website construction. I used it to build projects based on WordPress, Joomla, DNN, and other platforms, saving a lot of setup troubles, just click Next and enter some basic information.
This document describes how to use and read the SQL Server CE database in the WebMatrix project.
If you have heard about WebMatrix for the first time, refer to the first three articles in this series.
Body
1. Open WebMatrix and select site from Template, and then select Starter Site Template. Here I name the website Starter Site. Then click Files below to see the initial structure of the website.
2. Click Databases to create a database named starter. Select New Table from the menu, change the Table Name to Product, and add the New column Id and Name. Here we set Id as the primary key.
Different from SQL Server, there are very few attributes here.
After selecting Table product, click "Data" in the above menu. You can enter some Data to the Table:
3. Click Files to return to the file browsing view. Select About. Cshtml
Add the following two lines of code:
Var db = Database. Open ("starter ");
Var selectQueryString = "SELECT * FROM Product order by Name ";
Note that you do not need to set the connection string in web. config.
Add the following code to read all the data and display it on the webpage:
@ Foreach (var row in db. Query (selectQueryString ))
{
<Tr>
<Td>
@ Row. Id
</Td>
<Td>
@ Row. Name
</Td>
</Tr>
}
4. Click start to view about. cshtml:
Click here to download the source code
Thank you for reading this article
For more exciting articles, read ASP. NET (Alex Song)