Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
## I have added error codes at the end of the question, hope it might help you to help me.

Hi! there IT nerds, this old man needs some help big time.
I have an application that is suppose to search incidents and if needed export those search results to excel sheet. Searching part is fine. But while exporting, it will only export certain amount of data (seems like there is some kind of limitation). For example - if I want to search and export for 20 days worth of incident it will do just fine. If I search for 25 days, it will search fine but while exporting it will throw an exception. Is it because it is trying to export in the same way it is searching? I don't have much knowledge about asp.net and c#. These codes were written 10 years ago by some contractors. I don't know when the issue started as I just took over the application. Any feedback, comments, help will be highly appreciated. Below are the codes that being used:
C#
public partial class IncidentReviewLogExport : System.Web.UI.Page
{
#region Events
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        string REVN_SEQList = string.Empty;
        //Initalize dataset for catching return and load drop down list.
        DataSet ObjDataSet = new DataSet();
        //Initalize search incidents class object.
        WEIS.SearchIncidents ObjSearchIncidents = new WEIS.SearchIncidents();
        DataTable ObjDataTable = WEIS.SessionManager.Current.IncidentsDataTable;
        if (ObjDataTable == null)
        {
            #region Load details
            //Call method to get incidents.
            ObjDataSet = ObjSearchIncidents.GetIncidents(Convert.ToInt32(WEIS.SessionManager.Current.Selected_Mill_ID.ToString()),
                Request.QueryString["StartDate"].ToString(), Request.QueryString["EndDate"].ToString(), Request.QueryString["AllMills"].ToString(), Request.QueryString["EiscSeqs"].ToString(),
                Convert.ToInt32(Request.QueryString["Area"].ToString().Trim().Length == 0 ? "0" : Request.QueryString["Area"].ToString()),
                Request.QueryString["Status"].ToString().Trim().Length == 0 ? "0" : Request.QueryString["Status"].ToString(),
                Convert.ToInt32(Request.QueryString["EventType"].ToString().Trim().Length == 0 ? "0" : Request.QueryString["EventType"].ToString()),
                Convert.ToInt32(Request.QueryString["Instrument"].ToString().Trim().Length == 0 ? "0" : Request.QueryString["Instrument"].ToString()),
                Request.QueryString["EventGroupDisplayFlag"].ToString().Trim().Length == 0 ? "" : Request.QueryString["EventGroupDisplayFlag"].ToString());
            #endregion
            ObjDataTable = ObjDataSet.Tables[0];
        }
        if (ObjDataTable.Rows.Count > 0)
        {
            foreach (DataRow objDataRow in ObjDataTable.Rows)
            {
                REVN_SEQList = REVN_SEQList + objDataRow["REVN_SEQ"].ToString() + ",";
            }

            REVN_SEQList = REVN_SEQList.Remove(REVN_SEQList.Length - 1);

            //Initalize dataset for catching return and load drop down list.
            ObjDataSet = new DataSet();
            //Call method to get incidents for export.
            ObjDataSet = ObjSearchIncidents.GetIncidentsForExport(REVN_SEQList);

            //GrdViewIncidents.DataSource = ObjDataSet;
            //GrdViewIncidents.DataBind();

            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter stringWrite = new StringWriter();
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            GrdViewIncidents.AllowPaging = false;
            GrdViewIncidents.AllowSorting = false;
            GrdViewIncidents.DataSource = ObjDataSet.Tables[0];
            GrdViewIncidents.DataBind();
            GrdViewIncidents.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End();

           }
        else
        {
            Response.Write("There were no incidents found.");
        }
    }
}
public override void VerifyRenderingInServerForm(Control control)
{
    /* Verifies that the control is rendered */
}
#endregion
} 


//==============================================================
C#
#region GetIncidentsForExport
   public DataSet GetIncidentsForExport(string REVN_SEQList)
   {
       string StrStoredProcedureName = string.Empty;
       OracleParameter[] ObjArrOracleParameter = null;
       DataSet ObjReturnDataSet = new DataSet();
       try
       {
           ObjArrOracleParameter = new OracleParameter[2];
           StrStoredProcedureName = "K_SEARCHINCIDENTS.P_GETINCIDENTFOREXPORT"; //Resources.Resource.Search_Incidents_Get_Incident_For_Export;
           #region "Set Parameters for stored procedure"
           ObjArrOracleParameter[0] = new OracleParameter("P_REVN_SEQLIST", OracleDbType.Varchar2, ParameterDirection.Input);
           ObjArrOracleParameter[0].Size = 332767; //32767;
           ObjArrOracleParameter[0].Value = REVN_SEQList;

           ObjArrOracleParameter[1] = new OracleParameter("P_INCIDENTS", OracleDbType.RefCursor, ParameterDirection.Output);
           #endregion

           ObjReturnDataSet = DB_Manager.ExecuteDataset(DB_Manager.Get_ConnString(), CommandType.StoredProcedure, StrStoredProcedureName, ObjArrOracleParameter);

           foreach (DataRow ObjDataRow in ObjReturnDataSet.Tables[0].Rows)
           {
               if (ObjDataRow["DURATION"].ToString() == "DURATIONCALC")
               {
                   ObjDataRow["DURATION"] = Utilities.DurationCalculation(ObjDataRow["STARTED"].ToString(), ObjDataRow["STOPPED"].ToString(), ObjDataRow["SOURCE_TYPE"].ToString(), ObjDataRow["EVENT_TRIGGER"].ToString());
               }
           }

           return ObjReturnDataSet;
       }
       catch (Exception ex)
       {
           throw ex;
       }
   }
   #endregion

=============================================

I tried for few days but haven't been able to figure this out. I get the errors listed below:

C#
Source Error: 
An unhandled exception was generated during the execution of the current web request. 
Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
Stack Trace: 
[OracleException (0x80004005): ORA-01460: unimplemented or unreasonable 
conversion requested
ORA-06512: at "PADBA.K_SEARCHINCIDENTS", line 397
ORA-06512: at line 1]
WEIS.SearchIncidents.GetIncidentsForExport(String REVN_SEQList) +992
IncidentReviewLogExport.Page_Load(Object sender, EventArgs e) +2931
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint) +3178`


=======================================================

And line 397 looks like this:

C#
ObjArrOracleParameter[15] = new OracleParameter("P_INCIDENT_NUMBER",OracleDbType.Int32, ParameterDirection.Input);
ObjArrOracleParameter[15].Size = 5;
ObjArrOracleParameter[15].Value = IncidentNumber;
Posted
Updated 1-Feb-16 8:35am
v2

1 solution

You're sending an HTML string to the browser, but pretending that it's an Excel file. The might work in some circumstances, if Excel is willing to import the HTML file; but it's not correct.

You need to generate and send a real Excel file instead. There are various free libraries which will let you do this. For example:


Using EPPlus for example would look something like this:
C#
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;  filename=Sample1.xlsx");

var package = new ExcelPackage();
var sheet = package.Workbook.Worksheets.Add("Data");
sheet.Cells["A1"].LoadFromDataTable(ObjDataSet.Tables[0], true, TableStyles.Medium9);
package.SaveAs(Response.OutputStream);
Response.End();
 
Share this answer
 
Comments
AlfredoPasa 27-Jan-16 13:51pm    
Thank you Richard. I will try to make some changes with the instruction you have provided and let you know about the outcome shortly. I really appreciate your help.
AlfredoPasa 1-Feb-16 14:36pm    
I tried your approach and various different ways I found online but it is still not working. Any further guidance...Please..!!
Richard Deeming 1-Feb-16 14:41pm    
The errors you've just posted have nothing to do with the original question. You are now getting database errors from your stored procedure, which we can't see.

NB: The "line 397" in the error message refers to the line within the stored procedure, not the line within your C# code.
AlfredoPasa 1-Feb-16 15:13pm    
Interesting..may be I changed something while trying to fix...I will go back to original codes and try again. I wish I had someone like you in my team...I will not have to worry about this...anyway do you know any online resources that would be relevant to this. I found many but also have unnecessary information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900