SirReadAlot
asked on
preventing a method call
Hi experts,
I can’t get my head round this.
I want to stop this code from calling this method
this.displayBenefitGrid(sq
thanks
private void btnpayrollLink_Click(objec
{
OleDbConnection payrollDb;
SqlConnection adcDb;
bool errorsFound = false;
bool recordInserted= false;
payrollDb = null;
adcDb = null;
try
{
//payrolldb uses OLedb
payrollDb = new OleDbConnection(Configurat
//adcDb uses connection
adcDb = new SqlConnection(Configuratio
}
catch(Exception ex)
{
this.lblErrorDisplay.Text = ex.Message;
}
System.Collections.Hashtab
System.Data.SqlClient.SqlD
try
{
if (adcDb == null) this.lblErrorDisplay.Text = "Cannot access the ADC database. Contact the system administrator";
else
{
if (payrollDb == null) this.lblErrorDisplay.Text = "The payroll file was not found";
else
{
errorsFound = insertCompensationItems(ad
errorsFound = insertTaxPaid(adcDb,payrol
// this.DataGrid1.Visible=fal
//////////////////////////
///to show grid.
///
sqlDataReader = this.getBenefitInfo();
if ( sqlDataReader != null && sqlDataReader.HasRows)
this.displayBenefitGrid(sq
}
} //end else adcDb
}
catch(SqlException sex)
{
this.lblErrorDisplay.Text = "Database not found. Please contact the system administrator";
}
}
# endregion
ASKER
will try this what about this
private void btnpayrollLink_Click(objec t sender, System.EventArgs e)
{
OleDbConnection payrollDb;
SqlConnection adcDb;
bool InsertRecord = false;
bool errorsFound =false;
payrollDb = null;
adcDb = null;
try
{
//payrolldb uses OLedb
payrollDb = new OleDbConnection(Configurat ionSetting s.AppSetti ngs[this.d dEmployers .SelectedV alue]);
//adcDb uses connection
adcDb = new SqlConnection(Configuratio nSettings. AppSetting s["connect Local"]);
}
catch(Exception ex)
{
this.lblErrorDisplay.Text = ex.Message;
}
System.Collections.Hashtab le taxPaidList = new Hashtable();
System.Data.SqlClient.SqlD ataReader sqlDataReader;
try
{
if (adcDb == null) this.lblErrorDisplay.Text = "Cannot access the ADC database. Contact the system administrator";
else
{
if (payrollDb == null) this.lblErrorDisplay.Text = "The payroll file was not found";
else
{
errorsFound = insertCompensationItems(ad cDb,payrol lDb);
errorsFound = insertTaxPaid(adcDb,payrol lDb);
if (InsertRecord)
{
sqlDataReader = this.getBenefitInfo();
if ( sqlDataReader != null && sqlDataReader.HasRows)
this.displayBenefitGrid(sq lDataReade r);
}
else
{
this.displayBenefitGrid(nu ll);
}
}
} //end else adcDb
}
catch(SqlException sex)
{
this.lblErrorDisplay.Text = "Database not found. Please contact the system administrator";
}
}
# endregion
private void btnpayrollLink_Click(objec
{
OleDbConnection payrollDb;
SqlConnection adcDb;
bool InsertRecord = false;
bool errorsFound =false;
payrollDb = null;
adcDb = null;
try
{
//payrolldb uses OLedb
payrollDb = new OleDbConnection(Configurat
//adcDb uses connection
adcDb = new SqlConnection(Configuratio
}
catch(Exception ex)
{
this.lblErrorDisplay.Text = ex.Message;
}
System.Collections.Hashtab
System.Data.SqlClient.SqlD
try
{
if (adcDb == null) this.lblErrorDisplay.Text = "Cannot access the ADC database. Contact the system administrator";
else
{
if (payrollDb == null) this.lblErrorDisplay.Text = "The payroll file was not found";
else
{
errorsFound = insertCompensationItems(ad
errorsFound = insertTaxPaid(adcDb,payrol
if (InsertRecord)
{
sqlDataReader = this.getBenefitInfo();
if ( sqlDataReader != null && sqlDataReader.HasRows)
this.displayBenefitGrid(sq
}
else
{
this.displayBenefitGrid(nu
}
}
} //end else adcDb
}
catch(SqlException sex)
{
this.lblErrorDisplay.Text = "Database not found. Please contact the system administrator";
}
}
# endregion
sorry ignore my last post, didnt read question properly..
Hi, that'll work provided that you've checked for a null input in the displayBenefitGrid() method, i.e. if the parameter is null dont display anything otherwise display.
ASKER
hi,
i am try to stop the displayBenefitGrid from being called if an error occurs
""Hi, that'll work provided that you've checked for a null input in the displayBenefitGrid() method, i.e. if the parameter is null dont display anything otherwise display.""
private void displayBenefitGrid(SqlData Reader dataReader)
{
try
{
if (dataReader.HasRows)
{
this.lblInfo.Text = "The following items of compensation were added to the database. <a target='_blank' href='exceptionpage.aspx?E mployer=" + employerId +"'>Click here to view the error log</a>";
this.DataGrid1.DataSource = dataReader;
this.DataGrid1.DataBind();
this.btnExcelExport.Visibl e = true;
} else
this.lblInfo.Text = "Unable to add compensation items or no compensation items found";
}
catch
{
}
}
#endregion
i am try to stop the displayBenefitGrid from being called if an error occurs
""Hi, that'll work provided that you've checked for a null input in the displayBenefitGrid() method, i.e. if the parameter is null dont display anything otherwise display.""
private void displayBenefitGrid(SqlData
{
try
{
if (dataReader.HasRows)
{
this.lblInfo.Text = "The following items of compensation were added to the database. <a target='_blank' href='exceptionpage.aspx?E
this.DataGrid1.DataSource = dataReader;
this.DataGrid1.DataBind();
this.btnExcelExport.Visibl
} else
this.lblInfo.Text = "Unable to add compensation items or no compensation items found";
}
catch
{
}
}
#endregion
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if ( sqlDataReader != null && !sqlDataReader.HasRows)
You were displaying the grid if the reader had rows.