It’s about time to see what other things WebMatrix can do out of the box.
Let’s make something more.. personal.
Fire up webmatrix and create an Empty Website called.. “myContacts” then add one page, index.cshtml will do fine but I will name mine default.cshtml 😀
Mine looks like this:
Then we add a database. WebMatrix has database connectivity so why won’t we use it? Let’s go!
At the lower part of the webmatrix IDE, there is a Menu Item that says “Databases”. Click that and it will show you the databases page.
Right smack in the middle, you will find what looks to be a Hyperlink to add a database to our site. Click that and create a database for your contacts.
That action will give you a blank database, which is useless. So go ahead and create a table to hold the data for your contacts.
I made one table and it looks like this on my screen
Add some data
And we are set to go..
Here is the code:
var myDataSource = Database.Open(“myContacts”);
var myContactTable = myDataSource.Query(“Select * from tblContacts”);
@foreach(var contactInfo in myContactTable)
Run it. It works.