I was wondering if someone could help me out with this issue.
Basically I have a Web App, that searches a DB for a person based on an UID. After it finds the name, I open another db conn and search for their Managers email address.
However i'm getting the "Object reference not set to an instance" error, which i'm assuming something is null and it doesn't like it? that correct.
Here is my code.
public partial class Leaver : System.Web.UI.Page
{
string Managers_Name = null;
string Managers_Email = null;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_SearchDB(object sender, EventArgs e)
{
SqlDataReader reader = null;
SqlConnection conn = null;
try
{
conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["App_NewStarterConnectionString"].ConnectionString);
{
conn.Open();
using (SqlCommand cmd =
new SqlCommand("SELECT * FROM dbo.tb_starters WHERE Payrol = @Payrol", conn))
{
cmd.Parameters.AddWithValue("@Payrol", Payrol.Value);
reader = cmd.ExecuteReader();
while (reader.Read())
{
Fname.Value = reader["FirstName"].ToString();
Lname.Value = reader["LastName"].ToString();
Payrol.Value = reader["Payrol"].ToString();
section.Value = reader["Section"].ToString();
Managers_Name = reader["Manager"].ToString();
}
}
}
}
catch (Exception ee)
{
throw ee;
}
finally {
GetManagersEmail();
if (reader != null)
reader.Close();
if (conn.State == ConnectionState.Open)
conn.Close();
}
}
protected void GetManagersEmail()
{
SqlDataReader reader_new = null;
SqlConnection conn_new = null;
try
{
conn_new = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["App_NewStarterConnectionString"].ConnectionString);
{
conn_new.Open();
using (SqlCommand cmd = new SqlCommand("SELECT Email FROM dbo.tb_starters WHERE FullName = @ManagersName", conn_new))
{
cmd.Parameters.AddWithValue("@ManagersName", Managers_Name);
while (reader_new.Read())
{
Managers_Email = reader_new["Email"].ToString();
Response.Write(Managers_Email);
}
}
}
}
catch (Exception ee)
{
throw ee;
}
finally
{
if (reader_new != null)
reader_new.Close();
if (conn_new.State == ConnectionState.Open)
conn_new.Close();
}
}