Let’s first set up the database. Open Sql Server Management Studio Express and in the Object Explorer right click Databases >New Database. Choose a database name something like MyBlog. Leave Initial size and autogrowth at default. Drill down to your new database MyBlog in the Object Explorer on the left and right click Tables > New Table. Start filling in the column names and data types, starting off with EntryID with the datatype set at Integer. Set the EntryID as the primary key. In the properties dialogue box drill down till you see Identity Specification, expand and change Is Identity to Yes and set the Identity Increment to something like 4.
Next, back to the top in column name under EntryID enter Title with data type varchar(50) followed by Entry with data type text, Image with data type varchar(50) and finally Date with data type datetime. Make sure the Allow Nulls column is unchecked apart form the Image column. Save and close the table. Enter Entries as the name for the table.
Now let’s add some data to the table to get things moving along. Drill down to the MyBlog database expand tables and right click dbo.Entries > Open Table. Enter some data in the rows for example My first entry in the Title field, some Lorem Ipsum in the Entry field, the Image field Null and 01/01/200900:00:00 in the Date field. Repeat the exercise for a couple of more rows and save and close the table.
Ok, so now we have some data to work with. Open Visual Studio and select New Web Site and change the name from the default to something more appropriate like MyBlog. Next make sure you’re viewing the Server Explorer window, View > Server Explorer and expand Data Connections and drill down till you find "netsdk.MyBlog.dbo. Expand the MyBlog database and you will see your table Entries.
Open the solution explorer and right click App_Code and add new Folder naming the folder DAL. Next right click the DAL folder and choose Add New Item. From the list presented choose DataSet and change the name from DataSet1 to MyBlog. After a moment or two the TableAdapter Configuration wizard will open. Choose New Connection. In the Server name textbox type (Local)\NETSDK. Make sure select or enter a database name is selected and from the drop down list choose the MyBlog database. Click OK > Next. When asked whether you want to save the connection string to the application configuration file make sure that the yes box is checked. Click Next.
In the Choose a Command Type dialogue box choose Use SQL statements, then click Next and enter SELECT * FROM Entries. In the Choose Methods to Generate dialogue box Fill a Data Table and Return a Data Table should both be checked. Change the method name GetData to something like GetEntries and click Next > Finish. If all went well you should now be looking at the Data Table in design view. Change the name of the Data Table from Data Table 1 to EntryPosts and making sure that Fill,GetEntries is highlighted right clik and choose Preview Data. Click onto the preview button and the results will be displayed. Click Close.
Open the default page and while in design view drag a Grid View control from the toolbox save the page. Now, go to the code behind of the Default page and select Page Events and the declaration Load. Enter the following code block under the Page_Load event:
Dim PostAdapter As New MyBlogTableAdapter.EntryPostsTableAdapter
GridView1.DataSource = PostAdapter.GetEntries
GridView1.DataBind()
Save and run the project and you should see data displayed on the Web page.