当我单击生成Excel显示错误如下 [英] When i click the Generate Excel shows error as follows

查看:87
本文介绍了当我单击生成Excel显示错误如下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下;

My code as follows;

String Sql;
       SqlDataReader Dr;
       SqlDataCon Scon = new SqlDataCon();

       Label1.Text = "";
       try
       {
           if (CrsList.GetMajorCode.ToString().Trim() == null || CrsList.GetMajorCode.ToString().Trim() == "")
           {
               Label1.Text = "Invalid Course. Course is not selected";
               return;
           }

           if (CrsList.GetMinorCode.ToString().Trim() == null || CrsList.GetMinorCode.ToString().Trim() == "")
           {
               Label1.Text = "Invalid Sub Course. Course is not selected";
               return;
           }

           if (CrsList.GetBatchID.ToString().Trim() == null || CrsList.GetBatchID.ToString().Trim() == "")
           {
               Label1.Text = "Invalid Batch. Batch is not selected";
               return;
           }

    DataTable Dt = new DataTable();
           Sql = "OH_BatchWise_Collection_Report''" + CrsList.GetBatchID.ToString().Trim() + "''";
           Dr = Scon.ReadSql(Sql);
           Dt.Load(Dr);


  //Generating the Excel
           String attachment = "attachment; filename=collectiondetails.xls";
           Response.ClearContent();
           Response.ClearHeaders();
           Response.Clear();
           Response.Buffer = true;
           Response.Charset = "";

           Response.AddHeader("content-disposition", attachment);
           Response.ContentType = "application/vnd.ms-excel";
           Response.Write("");
           Response.Write("");
           Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");

           Response.Write("<head>");

           Response.Write("<style>\n");

           Response.Write("@page");
           Response.Write("{margin:.2in .2in .2in .2in;\n");

           Response.Write("mso-header-margin:.1in;\n");
           Response.Write("mso-footer-margin:.1in;\n");

           Response.Write("mso-page-orientation:landscape;}\n");
           Response.Write("</style>\n");

           Response.Write("<!--[if gte mso 9]><xml>\n");
           Response.Write("<x:excelworkbook xmlns:x="#unknown">\n");

           Response.Write("<x:excelworksheets>\n");
           Response.Write("<x:excelworksheet>\n");

           Response.Write("<x:name>Batchwisefeecollectiondetails</x:name>\n");
           Response.Write("<x:worksheetoptions>\n");

           Response.Write("<x:fittopage />");
           Response.Write("<x:scale>87</x:scale>");

           Response.Write("<x:print>\n");
           Response.Write("<x:validprinterinfo />\n");

           Response.Write("<x:papersizeindex>9</x:papersizeindex>\n");
           Response.Write("<x:horizontalresolution>600br mode="hold" />            Response.Write("<x:verticalresolution>600           Response.Write("</x:verticalresolution></x:horizontalresolution></x:print>\n");

           Response.Write("<x:selected />\n");
           Response.Write("<x:donotdisplaygridlines />\n");

           Response.Write("<x:protectcontents>False</x:protectcontents>\n");
           Response.Write("<x:protectobjects>False</x:protectobjects>\n");

           Response.Write("<x:protectscenarios>False</x:protectscenarios>\n");
           Response.Write("</x:worksheetoptions>\n");

           Response.Write("</x:excelworksheet>\n");
           Response.Write("</x:excelworksheets>\n");

           Response.Write("<x:windowheight>12780</x:windowheight>\n");
           Response.Write("<x:windowwidth>19035</x:windowwidth>\n");

           Response.Write("<x:windowtopx>0</x:windowtopx>\n");
           Response.Write("<x:windowtopy>15</x:windowtopy>\n");

           Response.Write("<x:protectstructure>False</x:protectstructure>\n");
           Response.Write("<x:protectwindows>False</x:protectwindows>\n");

           Response.Write("</x:excelworkbook>\n");
           Response.Write("</xml><![endif]-->\n");

           Response.Write("</head>");

           Response.Write("<body>");
           Response.Write("<table>");

           Response.Write("<tr>");
           Response.Write("<td colspan="16"><center>");
           Response.Write("<font size="4" face="Arial">HIMT COLLEGE</font>");
           Response.Write("</center></td>");
           Response.Write("</tr>");

           Response.Write("<tr>");
           Response.Write("<td colspan="16"><center><font size="3" face="Arial">");
           Response.Write("Batch wise fee collection details - " + CrsList.GetMinorCode.ToString().Trim() + " - " + CrsList.GetBatchDate.ToString());
           Response.Write("</font></center></td>");
           Response.Write("</tr>");

           Response.Write("</table>");

           Response.Write("<table border="1" bordercolor="black">");
           Response.Write("<tr style="height:16pt">");

           foreach (DataColumn dc in Dt.Columns)
           {
               Response.Write("<td><center><font face="Arial"> ");
               Response.Write(dc.ColumnName);
               Response.Write("</font></center></td>");
           }
           Response.Write("</tr>");

  foreach (DataRow row in Dt.Rows)
           {
               Response.Write("<tr style="height:16pt">");
               for (int i = 0; i < Dt.Columns.Count; i++)
               {
                   if (i == 0)
                       Response.Write("<td><center><font face="Arial">" + row[i].ToString().Trim() + "</font></center></td>");
                   else
                       Response.Write("<td><left><font face="Arial">" + row[i].ToString().Trim() + "</font></left></td>");
               }
               Response.Write("</tr>");
           }

           Response.Flush();
           Response.Write("</table>");
           Response.Write("</body>");
           Response.Write("</html>");
           Response.End();

           HttpContext.Current.ApplicationInstance.CompleteRequest();
       }
       catch (Exception ex1)
       {
           Label1.Text = ex1.ToString();
           return;
       }







我在Generate Button中写了上面的代码。当我点击生成按钮我想要excel中的记录我写了上面的代码。



但是当我点击Generate按钮显示错误如下;



无法评估表达式,因为代码已经过优化,或者本机框架位于调用堆栈之上。





请帮帮我。我上面的代码有什么问题。



谢谢,

问候,

Narasiman P.




I written the above code in the Generate Button.when i click the Generate Button i want the records in excel for that i written the above code.

But when i click the Generate button shows error as follows;

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.


please help me. what is the problem in my above code.

Thanks,
Regards,
Narasiman P.

推荐答案

你还没有提到哪一行会导致问题,但是因为已知问题,Response.End()我猜它就是这样。您应该阅读以下来自Microsoft的文章 http://support.microsoft.com/kb/312629/en-us [ ^ ]
You haven''t mentioned which line causes the problem but as there is a known problem with Response.End() I''m guessing it''s that. You should read the following article from microsoft http://support.microsoft.com/kb/312629/en-us[^]


这篇关于当我单击生成Excel显示错误如下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆