Farhan Shariff

Farhan Shariff

  • NA
  • 933
  • 237.7k

Pass string value to catch (Inner exceptions)

Aug 5 2014 10:41 AM
I have this function which compares two DataTables (table1 and table2 )and makes a a new table3( sorted in ascending order)

1.Here table2 should have only numeric(double) values but whenever there is a non numeric value I want to display the column name(col).

private static DataTable CompareTwoDataTable(DataTable table1, DataTable table2)
        {


            DataTable returnValue = null;
         
            try
            {
                DataTable table3 = new DataTable();
                DataRow dr = null;
                string filterExp = string.Empty;
                for (int i = 0; i < table1.Rows.Count; i++)
                {


               string col = table1.Rows[i]["Par Name"].ToString(); // column names of table2
                    if (table2.Columns.Contains(col) )
                    {
                        if (!table3.Columns.Contains(col))
                        {
                            table3.Columns.Add(col, typeof(double));
                            filterExp = filterExp + col + " asc ,";
                        }


                        for (int j = 0; j < table2.Rows.Count; j++)
                        {
                            if (table3.Rows.Count != table2.Rows.Count)
                            {
                                dr = table3.NewRow();
                                table3.Rows.Add(dr);
                            }
/*Here I want to check if the value begin copied is numeric(double) else I want               to display the col (ie column name in table2)whenever there is a non numeric  value control is transferred to catch how to pass col to catch */


                           table3.Rows[j][col] = table2.Rows[j][col];
                     
                        }

                    }

                }
           
                returnValue = resultDt;
          }

     catch
            {
               
MessageBox.Show("Critical Data error caused by "+ "\n" 1.String Value Present in the Parametric Data", "- Exit Application ", MessageBoxButtons.OK, MessageBoxIcon.Error);
             
               MessageBox.show("Column with non numeric data :" +_______ );
             
                Environment.Exit(0);


            }
           
            return returnValue;
            }

Answers (15)