default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GuestBook
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void signGuests_Click(object sender, EventArgs e)
{
guestForm.Visible = false;
Guests curGuests = new Guests();
string signResult = curGuests.signGuest(last.Text, first.Text);
outputBox.Text = signResult;
}
protected void showGuests_Click(object sender, EventArgs e)
{
guestForm.Visible = false;
Guests guestList = new Guests();
string signResult = guestList.showGuests();
outputBox.Text = signResult;
}
}
}
Guests.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
/*
* This is where the database access code resides
*/
namespace GuestBook.App_Code
{
public class Guests
{
//open connection to database
private SqlConnection dbConnection = new SqlConnection("Data Source=.\\SQLEXPRESS;Integrated Security=True;User Instance=True");
//insert names into database
public string signGuests (string lastName, string firstName)
{
string results = "";
try
{
string hitInfo = "INSERT INTO guests Values('" + firstName + "', '" + lastName + "')";
SqlCommand updateCommand = new SqlCommand(hitInfo, dbConnection);
updateCommand.ExecuteNonQuery();
results = "

Thank you for signing our guest book

";
}
catch (SqlException exception)
{
results = "

Error code " + exception.Number + "; " + exception.Message + "

";
}
return results;
}
//Retreive names from database
public string showGuests()
{
string guestList = "";
string SQLString = "SELECT firstName, lastName FROM guests";
SqlCommand guestTable = new SqlCommand(SQLString, dbConnection);
SqlDataReader guestRecords = guestTable.ExecuteReader();
if (guestRecords.Read())
{
guestList = "

The following visitors have signed our guest book:

";
guestList = "";
guestList = "FirstNameLast NAme";
do
{
guestList += "" + guestRecords["firstName"] + "";
guestList += "" + guestRecords["lastName"] + "";
} while (guestRecords.Read());
guestList += "";
}
else
guestList = "

There are no entried in the guest book!

";
return guestList;
}
//open database file
public Guests()
{
dbConnection.Open();
dbConnection.ChangeDatabase("C: \\Users\\IU Student\\source\\repos\\GuestBook\\App_Data\\Guest.mdf");
}
//close database
~Guests()
{
dbConnection.Close();
}
}
}
The error I am getting I cannot figure out, I really need some help!
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'Guests' could not be found (are you missing a using directive or an assembly reference?) GuestBook C:\Users\IU Student\source\repos\GuestBook\default.aspx.cs 20 Active
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'Guests' could not be found (are you missing a using directive or an assembly reference?) GuestBook C:\Users\IU Student\source\repos\GuestBook\default.aspx.cs 20 Active
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'Guests' could not be found (are you missing a using directive or an assembly reference?) GuestBook C:\Users\IU Student\source\repos\GuestBook\default.aspx.cs 28 Active
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'Guests' could not be found (are you missing a using directive or an assembly reference?) GuestBook C:\Users\IU Student\source\repos\GuestBook\default.aspx.cs 28 Active