Unable to find table 0 ASP.NET

Asked

Viewed 530 times

0

I’m developing a screen that exports processed data from a Procedure for PDF/Xls. Debugging it returns the following error:

Unable to find table 0

From what I understand he can’t read the instantiated class on an object. I wonder what can cause this kind of error I mentioned.

Follows codes:

Event of importing XLS( the type of report I am using is the "saldoest"):

 protected void btnImpListaXLS_Click(object sender, ImageClickEventArgs e)
{
    try
    {
        Estoque objEstoque = new Estoque();
        switch (ddlTipoRelatorio.SelectedValue)
        {
            case "saldo":
                SetarFiltrosRptSaldoAtualEstoque();
                break;
            case "curva":
                objEstoque.ProcessarProcRelCurvaABC(SetarFiltroCurvaABC());
                break;
            case "esgotados":
                objEstoque.ProcessarProcEsgotados(SertarFiltroEsgostados());
                break;
            case "movimentacao":
                switch (rdbMovimentacao.SelectedValue)
                {
                    case "analitico":
                        SetarParametroMovimentacaoAnalitica();
                        break;
                    case "sintetico":
                        objEstoque.ProcessarRelatorioMovimentacaoSintetica(SetarParametroMovimentacaoSintetico(objEstoque));
                        break;
                    case "notasFiscais":
                        SetarParametroMovimentacaoNotasFiscais();
                        break;
                }
                break;
            case "custoVendas":
                objEstoque.ProcessarRelatorioCustoVendas(SetarFiltrosCustoVendas());
                break;
            case "valProd":
                ProcessarValidadeProdutos(objEstoque, "xls");
                return;
            case "saldoest":
                objEstoque.ProcessarSaldoAtualEstoqueEmpresa(SetarFiltrosEstoqueEmpresa());
                break;
        }

Setarfiltrosestoqueempresa():

 public SqlParameter[] SetarFiltrosEstoqueEmpresa()
{
    try
    {
        SqlParameter[] param = new SqlParameter[]
        {
            new SqlParameter("@EmpInicial", txtEmpresaIni.Text),
            new SqlParameter("@EmpFinal", txtEmpresaFim.Text),
            new SqlParameter("@DataInicio", Convert.ToDateTime(txtDataIni.Text).ToString("yyyy-MM-dd")),
            new SqlParameter("@DataTermino", Convert.ToDateTime(txtDataFinal.Text).ToString("yyyy-MM-dd")),
            (string.IsNullOrEmpty(txtProdInicial.Text) ? new SqlParameter("@ProdInicial",DBNull.Value): new SqlParameter("@ProdInicial", txtProdInicial.Text)),
            (string.IsNullOrEmpty(txtProdFinal.Text) ? new SqlParameter("@ProdFinal", DBNull.Value): new SqlParameter("@ProdFinal", txtProdFinal.Text))
        };
        metodos.rpt = "SaldoEstoqueEmpresa.rpt";
        metodos.nomeFormula = new string[2];
        metodos.valorFormula = new string[2];         
        metodos.nomeFormula[0] = "Empresa";
        Empresa objEmpresa = new Empresa();
        if (objEmpresa.ConsultarEmpresa((string)Session["empresa"]) > 0) { metodos.valorFormula[0] = objEmpresa.ParEmpresa; }
        else { metodos.valorFormula[0] = string.Empty; }
        metodos.nomeFormula[1] = "Filtro";
        metodos.valorFormula[1] = "Produtos de " + txtProdInicial.Text + " à " + txtProdFinal.Text + " Periodo de " + txtDataIni.Text + " à " + txtDataFinal.Text;
        return param;
    }
    catch (Exception)
    {
        throw;
    }
}

ProcessarSaldoAtualEstoqueEmpresa():

 public void ProcessarSaldoAtualEstoqueEmpresa(SqlParameter[] param)
    {
        try
        {
            strSql = new StringBuilder();
            strSql.Append("ProcSaldoEstoqueEmp");
            SqlDAO.executarSQLProc(strSql, param);
        }
        catch (SqlException ex)
        {
            throw ex;
        }
        catch (Exception)
        {

            throw;
        }
    }

Executarprocsql method:

        public static int executarSQLProc(StringBuilder strSql, params SqlParameter[] parametros)
    {
        SqlConnection con = null;
        try
        {
            SqlCommand cmd;
            con = abrirConexao();
            cmd = new SqlCommand(strSql.ToString(), con);

            using (cmd)
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddRange(parametros);
                cmd.CommandTimeout = 300;
                int nRegs = cmd.ExecuteNonQuery();
                cmd.Dispose();
                return nRegs;
            }
        }
        catch (SqlException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            fecharConexao(con);
        }
    }
  • what the code of SqlDAO.executarSQLProc(strSql, param); ??

  • @Rovannlinhalis parameters "param" are set in the method SetarFiltrosEstoqueEmpresa(). When proc is executed the data would be so exec ProcSaldoEstoqueEmp '01','03','2017-05-01','2017-05-20','1003','1003'

  • yes, that I followed, I want to know the method code executarSQLProc

  • @Rovannlinhalis I edited in question

  • I can’t see it now, but I recommend you take out all the try-catch of your code, they’re just escalating the problem. I only use them when I learn how and when to use them. Zero try-catch It’s not good, but it’s a minor mistake to put all these without need. https://answall.com/q/30124/101 and https://answall.com/q/186617/101. I have also seen one StingBuilder completely unnecessary and slightly harmful. I see other things that could be better in this code. Call Dispose() in the hand inside using is error, call fecharConexao() it’s probably a mistake too.

  • 1

    One of the reasons I couldn’t help is I couldn’t find query. In the new edition code I saw more problems.

  • apparently the code is ok, follow the advice of the bigown there removing that lot of Try-catch and also post the query of the Procedure; The exception is being thrown by the code or by the bank ?

  • @Rovannlinhalis is being released by code

  • at what time ? if you can show the stack trace

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.