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);
??– Rovann Linhalis
@Rovannlinhalis parameters "param" are set in the method
SetarFiltrosEstoqueEmpresa()
. When proc is executed the data would be so execProcSaldoEstoqueEmp '01','03','2017-05-01','2017-05-20','1003','1003'
– Igor Carreiro
yes, that I followed, I want to know the method code
executarSQLProc
– Rovann Linhalis
@Rovannlinhalis I edited in question
– Igor Carreiro
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. Zerotry-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 oneStingBuilder
completely unnecessary and slightly harmful. I see other things that could be better in this code. CallDispose()
in the hand insideusing
is error, callfecharConexao()
it’s probably a mistake too.– Maniero
One of the reasons I couldn’t help is I couldn’t find query. In the new edition code I saw more problems.
– Maniero
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 ?
– Rovann Linhalis
@Rovannlinhalis is being released by code
– Igor Carreiro
at what time ? if you can show the stack trace
– Rovann Linhalis