Datatable Lento

Asked

Viewed 124 times

1

Good Afternoon, You Guys

I have the routine below. I would need to streamline this routine it takes a long time to process, someone would tell me how I could do it ?

The Select performed in the dsParam Dataset can bring more than 1 line.

                    DataTable dtEndereco = new DataTable();

                    foreach (DataRow drEnd in dsParam.Tables["Endereco"].Select(string.Format("ID = {0} AND Documento = '{1}'", drNotas["ID"].ToString(), Documento)))
                    {
                        dtEndereco.ImportRow(drEnd);

                        dtEndereco.Rows[l]["ID"] = int.Parse(ID_Ini) * -1;
                        dtEndereco.Rows[l]["Documento"] = Documento_Ini;
                        l++;
                    }
  • 1

    Hello Mark, your query returns how many records?

  • Have you analyzed if what it takes to generate Datatable or foreach? If this is the query you will need more details of the database and the database that generates Datatable.

  • It’s Foreach, I ran that analysis

  • @Marcosmuekita, so your poblema is in the DataSet dsParam. But to help you will need more information.

  • What information do you need? The solution that Carlos gave me did not resolve the slowness. If anyone can help me thank you

1 answer

-2

try to get Xpression out of the foreach, something like that:

    ...    

DataSet dsParam;
DataTable dt = dsParam.Tables["Endereco"];
DataRow[] rows;
string  expression = string.Format("ID = {0} AND Documento = '{1}'", drNotas["ID"].ToString(), Documento);

rows = table.Select(expression);
foreach (DataRow drEnd in rows)
{
   dtEndereco.ImportRow(drEnd);
   dtEndereco.Rows[l]["ID"] = int.Parse(ID_Ini) * -1;
   dtEndereco.Rows[l]["Documento"] = Documento_Ini;
   l++;
 }

Browser other questions tagged

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