Since I’ve done absolutely no prep for this exam, I figured I’d do so in here. Here’s the mock. Usually I’d say break down what you’re being asked to do, but it seems like they’ve already done that for us.
Create a website. First thing I’d do is insert the database class we need to be using. (Looks like an informal CC GNU GPL, so long as he keeps credit.) Do that by copying the text – all of it. Going back to Visual Studio, right clicking on your project, Add new item…, Class, Yes to the “Put it in the ‘App code’ folder”. Select everything, and paste the contents of that Word document for the table class (overwriting everything that was there). Rename that class to something more logical.
We also need to add the yabba database we’ve been given. Right click App_Data, Add existing item…, find and insert the database we’ve been given.
Add two fields, like it says, for the name and message. Validate inputs. I’ve no idea howwhy you’d use a function to validate two strings though, so I’m not going to.
Now, uhh… lets find how to use this database thing. I’m sure there was a class on it. Yep, here’s the presentation on it: Database and webservers. Written by Mathew Dean. Slide 13 gives you the code to connect to a database. And he talks about adding records here, on slide 2 and onwards.
Just to explain what this class actually does. When you create it, it nabs all the records and puts them into a hashed array (which has a key, and a value, rather than just an index number and a value). You add to that array like normal, using NewRecord, and then when you save it just updates the database according to that array of information.
Okay, I’m actually bored of this now.
Here’s the badly commented code for the first page.
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
' As if we're in C, variables at the top, for no reason. Regaurdless of if we need them. Which we don't.
Dim Name As String
Dim Message As String
' Make sure neither textbox is empty
If (txtName.Text <> "" And txtMessage.Text <> "") Then
Name = txtName.Text
Message = txtName.Text
'Connect to the database
Dim MessagesDatabase As New DatabaseTable("yabba.mdb", "tblMessages")
MessagesDatabase.NewRecord.Item("PostedBy") = Name
MessagesDatabase.NewRecord.Item("MessageText") = Message
MessagesDatabase.AddNewRecord()
MessagesDatabase.SaveChanges()
Response.Redirect("second.aspx")
Else
lblStatus.Text = "Something was empty. Try again."
End If
End Sub
Second.aspx is supposed to output all the messages. Have fun with that.
