0

I have a DataTable with two values that are obtained from DataGridView:

  • Código
  • Denominación

Now, I want to do a query to a Database and get two new values for every code:

  • Caract
  • Valor

What I'm doing is create a new datatable and store there the values Caract and Valor, so I have to DataTable, one with Código and Denominación and another one with Caract and Valor.

**What you should recommmend me? Introduce the new values in the first datatable or create these two datatables and try to join them.

This is my code:

1) Intranet.list1 have all the codes

2) caracSeleccionadas have all the features.

foreach (DataRow row in Intranet.list1.Rows)
        {
            for (int i = 0; i < caracSeleccionadas.Count; i++)
            {

                conexion = new SqlConnection(connString);
                conexion.Open();
                //la denominación se obtiene de otra tabla
                strsql = "";
                strsql = strsql + " SELECT  CARACT, VALOR";
                strsql = strsql + " FROM    T_ARTCAR";
                strsql = strsql + " WHERE   CODIGO = '" + row["Code"].ToString() + "' AND CARACT = '" + caracSeleccionadas[i].ToString() + "'";
                System.Diagnostics.Debug.WriteLine(" query: " + strsql);
                comando = new SqlCommand(strsql, conexion);
                adapter = new SqlDataAdapter(comando);
                table = new DataTable();

                comando.CommandText = strsql;
                table.Columns.Clear();
                table.Clear();
                adapter.Fill(table);

                dtExcelInforme.Rows["Característica"] = "";
Hassan Hosseini
  • 573
  • 1
  • 3
  • 20
LuckWallace
  • 103
  • 7
  • Does this answer your question? [How can I add a new column and data to a datatable that already contains data?](https://stackoverflow.com/questions/2312966/how-can-i-add-a-new-column-and-data-to-a-datatable-that-already-contains-data) – Sushant Yelpale Jan 02 '20 at 11:56
  • Some advice regarding your SQL: https://stackoverflow.com/questions/601300/what-is-sql-injection – Crowcoder Jan 02 '20 at 12:57

0 Answers0