0) Put your code in a
try/catch
block.
1) At the top of the
try
block, put this like
if (string.IsNullOrEmpty(Session["id"])) { throw new Exception("Session ID has not been set");}
2) Run the code under the debugger with a breakpoint set in the
catch
block.
3) Your code is generally not really built well. Do it this way instead:
try
{
if (string.IsNullOrEmpty(Session["id"]))
{
throw new Exception("Session ID has not been set");
}
using (SqlConnection con = new SqlConnection("Data Source=USER-PC;Initial Catalog=1GCAttendanceManagementSystem;Integrated Security=True"))
{
DataTable dt = new DataTable();
con.Open();
SqlDataReader myReader = null;
using (SqlCommand myCommand = new SqlCommand("select * from Employee where EmpUsername='" + Session["id"] + "'", con){CommandType=CommandType.Text})
{
myReader = myCommand.ExecuteReader();
if (!myReader.HasRows)
{
}
while (myReader.Read())
{
txtCode.Text = (myReader["EmployeeId"].ToString());
txtUsername.Text = (myReader["EmpUsername"].ToString());
txtPass.Text = (myReader["EmpPassword"].ToString());
txtEmail.Text = (myReader["EmpEmail"].ToString());
txtFirstname.Text = (myReader["EmpFirstName"].ToString());
txtLastname.Text = (myReader["EmpLastName"].ToString());
txtGender.Text = (myReader["EmpGender"].ToString());
txtContact.Text = (myReader["EmpContact"].ToString());
txtAddress.Text = (myReader["EmpAddress"].ToString());
txtDept.Text = (myReader["EmpDept"].ToString());
}
}
}
}
catch (Exception ex)
{
}