C# 2008 object instance problem. Please help?
So I am having a bit of a problem here with a class assignment I'm doing. Yes we have to use visual studio 2008. It's a payroll system that stores the employees name, pay rate, start date, and end date into a database. Now everything executes fine until I start inputting the information. It says "NullReferenceException was unhandled by user code" with the following description: "Object reference not set to an instance of an object".
Data layer code:
// This function saves the personnel data
public static bool SavePersonnel(string Database, string FirstName, string LastName,
string PayRate, string StartDate, string EndDate)
{
bool recordSaved;
try
{
// Add your comments here
OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Database);
conn.Open();
OleDbCommand command = conn.CreateCommand();
string strSQL;
// Add your comments here
strSQL = "Insert into tblPersonnel " +
"(FirstName, LastName, PayRate, StartDate, EndDate) values ('" +
FirstName + "', '" + LastName + "', " + PayRate + ", '" + StartDate +
"', '" + EndDate + "')";
// Add your comments here
command.CommandType = CommandType.Text;
command.CommandText = strSQL;
// Add your comments here
command.ExecuteNonQuery();
//closes connection
conn.Close();
recordSaved = true;
}
catch (Exception ex)
{
recordSaved = false;
}
return recordSaved;
}
Here is the frmPersonnelVerified verifying code
// saving the personnel information
if (clsDataLayer.SavePersonnel(Server.MapPath("PayrollSystem_DB.mdb"),
Session["txtFirstName"].ToString(),
Session["txtLastName"].ToString(),
Session["txtPayRate"].ToString(),
Session["txtStartDate"].ToString(),
Session["txtEndDate"].ToString()))
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\nThe information was successfully saved!";
}
else
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\nThe information was NOT saved.";
}
Now when I click "continue" my webpage shows this line of code highlighted:
if (clsDataLayer.SavePersonnel(Server.MapPath("PayrollSystem_DB.mdb"),
Any tips? If you need more information I'll give more.
typo:
If you can't see past the "Server.MapPath", this is what it looks like:
Server.MapPath("PayRollSystem_DB.mdb")
@Mike: I don't expect you to trace it, I just thought it was obvious. I apologize, the line that is highlighted says line 33 in my program "if(clsDataLayer.SavePersonnel(Server.MapPath("PayRollSystem.DB.mdb")" at the bottom of my question.
@Rachet: According to quick watch...it says that all the "txt####" do not exist in the current context...great....