I've got some code that I'm trying to enclose in a try/catch block. This
code is in the Page_Load() method of the code-behind for an .aspx page.
On the line where the "try" keyword is, I'm getting the error "Object
reference is not set to an instance of an object". Why would I get that on
the "try" keyword. I've copied the code below, and you can see that I've
commented out the extra code to the point where all I have is the
Page_Load() event and the try/catch block. What could be causing this?
public void Page_Load(object sender, System.EventArgs e)
{
//string sSQL;
try
{
/*
OleDbConnection2.Open();
sSQL = "SELECT Statement_Id,Statement_In_Brief FROM Statements";
daStatements = new OleDbDataAdapter(sSQL,OleDbConnection1);
daStatements.Fill(dsStatements);
Response.Write( "Record count = " +
dsStatements.Tables[0].Rows.Count.ToString());
string sSQL = "SELECT Statement_Id,Statement_In_Brief FROM Statements";
daStatements = new OleDbDataAdapter(sSQL,OleDbConnection1);
daStatements.Fill(dsStatements,"Statements");
DropDownList1.DataSource = dsStatements.Tables["Statements"];
DropDownList1.DataTextField = "Statement_In_Brief";
DropDownList1.DataValueField = "Statement_ID";
DropDownList1.DataBind();
Response.Write("test");
OleDbConnection1.Close();
*/
}
catch(Exception e)
{
//Response.Write(e.ToString);
}
} // end Page_Load() event