Dear Sir
Can you please help me out on this Error : Cannot find table 1.
I am using Asp.net C# Webforms.
protected void BtnExcel_Click(object sender, EventArgs e)
{
try
{
str = " SELECT DISTINCT ROUTE_CODE FROM CT_CUSTOMER_MIS WHERE DIV_CODE='" + Session["DivCode"].ToString() + "' AND BRANCH_CODE='" + ddlBranchCode.SelectedValue + "' " +
" AND CUSTOMER_CODE='" + ddlCustomer.SelectedValue.Split('>')[0].ToString().Trim() + "' ORDER BY ROUTE_CODE ";
DataSet ds = oper.DTSET(str);
XLWorkbook wb = new XLWorkbook();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ds.Tables[i].TableName = ds.Tables[0].Rows[i][0].ToString();
string str2 = " SELECT SR_NO,ROUTE_CODE,ROUTE_DESC,INVOICE_NO,TO_CHAR(INVOICE_DATE,'dd-Mon-yyyy')INVOICE_DATE,DISPATCH_DATE,PICKUP_CODE,DELIVERY_CODE,DEALER_CODE, " +
" REGIS_NO,FLEET_TYPE,DSL_FLG,DSL_AMNT,QNTY,MNF_NUMBER,HSN_CODE,NVL(RATE,0)RATE,NVL(TOTAL,0)TOTAL FROM CT_CUSTOMER_MIS WHERE DIV_CODE='" + Session["DivCode"].ToString() + "' AND BRANCH_CODE='" + ddlBranchCode.SelectedValue + "' " +
" AND CUSTOMER_CODE='" + ddlCustomer.SelectedValue.Split('>')[0].ToString().Trim() + "' AND ROUTE_CODE='" + ds.Tables[0].Rows[i][0].ToString() + "' ORDER BY SR_NO ";
br = oper.DTSET(str2);
for (int k = 0; k < br.Tables[0].Rows.Count; k++)
{
wb.Worksheets.Add(br.Tables[k], br.Tables[k].TableName);
}
}
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=ddlCustomer.SelectedValue.Split('>')[1].ToString().Trim().xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
catch (Exception ex)
{
string s = ex.Message;
s = s.Replace("\"", "");
s = s.Replace("'", "");
s = s.Replace("\r", "\\r");
s = s.Replace("\n", "\\n");
ScriptManager.RegisterStartupScript(this, typeof(Page), "Error", "<script>showpop6('" + s + "')</script>", false);
}
}