0
Answer

retrieving the store procedure result display into excel

narasiman rao

narasiman rao

11y
928
1

 
   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 course. Course is not selected";
return;
}
 
if (CrsList.GetBatchDate.ToString().Trim() == null || CrsList.GetBatchDate.ToString().Trim() == "")
{
Label1.Text = "Invalid Batch. Batch is not selected";
return;
}
 

DataTable Dt = new DataTable();
Sql = "OH_BatchWise_Collection_Report_Psea'" + 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("<body>");
  Response.Write("<table>");

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

            Response.Write("<tr>");
            Response.Write("<td colspan=8><center><b><Font size=3 face='Arial'>");
            Response.Write("Batch wise fee collection details- " + CrsList.GetMinorCode.ToString().Trim() + " - " + CrsList.GetBatchDate.ToString());
            Response.Write("</font></b></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("");
}
Response.Write("");
 
try
{
Response.Flush();
Response.Write("</table>");
                Response.Write("</body>");
                Response.Write("</html>");
                //Response.End();
            }
            catch (Exception ex1)
            {
                Label1.Text = ex1.ToString();
                return;
            }

            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
        catch (Exception ex1)
        {
            Label1.Text = ex1.ToString();
            return;
        }
 
Design page in run mode as follows;
 
Dropdownlist (All Course name is there)
 
Listbox1 Listbox2

In Listbox 1 all the sub course are present 
In Listbox 2 batch date of sub course are present.
 
In the run mode when i select the course from the downlist, in the listbox1 subcourse are present and select the sub course from listbox1 then batchdate are present in the listbox2.
 
Then i click the Generate button that particular batch date of course want to show in the excel.
 
for that saving the data in the excel i written the code above.
 

But i click the Generate Button that particular batch date of course excel is not opening.
what is the problem in my above code.

from my above code what is the problem please help me.
 
Regards,
Rao