private ExecuteResults GetDataToFillDataGrid(object sender, DoWorkEventArgs e)
        {
            ExecuteResults results = new ExecuteResults();

            mod_execParam = (ExecuteParameters)e.Argument;

            try
            {
                // if provider is not specified use sqlconncetion
                if (!mod_execParam.ConnectionString.ToLower().Contains("provider=") && !mod_execParam.ConnectionString.ToLower().Contains("provider ="))
                {
                    using (SqlConnection sqlCon = new SqlConnection(mod_execParam.ConnectionString))
                    {
                        sqlCon.Open();

                        using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(
                                   mod_execParam.SqlStatement, sqlCon))
                        {
                            mod_dtblDBTables = new DataTable();
                            sqlAdapter.Fill(mod_dtblDBTables);
                            // Render data onto the screen
                            results.ResultsData = mod_dtblDBTables;
                            mod_sAdapterSource  = "SQL";
                        }
                    }
                }
                else
                {
                    using (OleDbConnection oleCon = new OleDbConnection(mod_execParam.ConnectionString))
                    {
                        oleCon.Open();

                        using (OleDbDataAdapter oleAdapter = new OleDbDataAdapter(
                                   mod_execParam.SqlStatement, oleCon))
                        {
                            mod_dtblDBTables = new DataTable();
                            oleAdapter.Fill(mod_dtblDBTables);
                            results.ResultsData = mod_dtblDBTables;
                            mod_sAdapterSource  = "OLE";
                        }
                    }
                }
                //Console.Beep();
                results.StatusMessage = "Completed in " + (DateTime.Now - _dtNow) + ". ";
            }
            catch (Exception ex)
            {
                results.ExceptionDetails = ex;
                results.StatusMessage    = "Completed with errors in " + (DateTime.Now - _dtNow) + ". ";
            }

            if (results.ResultsData != null)
            {
                results.StatusMessage = results.StatusMessage + results.ResultsData.Rows.Count + " row(s) returned. ";
            }

            return(results);
        }
        private void FillDataGrid(ExecuteResults results)
        {
            if (results.ExceptionDetails != null)
            {
                mod_dtblTable = new DataTable();

                mod_dtblTable.Columns.Add("Exception", typeof(String));
                mod_dtblTable.Columns.Add(" ", typeof(String));

                mod_dtblTable.Rows.Add("Message", results.ExceptionDetails.Message);
                mod_dtblTable.Rows.Add("StackTrace", results.ExceptionDetails.StackTrace);
                mod_dtblTable.Rows.Add("Source", results.ExceptionDetails.Source);
                mod_dtblTable.Rows.Add("Data", results.ExceptionDetails.Data);

                //add inner exception if any
                if (results.ExceptionDetails.InnerException == null)
                {
                    mod_dtblTable.Rows.Add("Inner Exception", "null");
                }
                else
                {
                    mod_dtblTable.Rows.Add("Inner Exception Message", results.ExceptionDetails.InnerException.Message);
                    mod_dtblTable.Rows.Add("Inner Exception StackTrace", results.ExceptionDetails.InnerException.StackTrace);
                    mod_dtblTable.Rows.Add("Inner Exception Source", results.ExceptionDetails.InnerException.Source);
                    mod_dtblTable.Rows.Add("Inner Exception Data", results.ExceptionDetails.InnerException.Data);
                }

                dgrid_TableData.DataSource = mod_dtblTable;
                toolStripStatusLabel1.Text = results.StatusMessage;

                btnScriptTableData.Enabled      = false;
                chkTruncateFirst.Enabled        = false;
                btnClearDataTableFilter.Enabled = false;
            }
            else
            {
                mod_dtblTable = results.ResultsData;
                dgrid_TableData.DataSource      = mod_dtblTable;
                toolStripStatusLabel1.Text      = results.StatusMessage;
                btnScriptTableData.Enabled      = true;
                btnClearDataTableFilter.Enabled = true;
                chkTruncateFirst.Enabled        = true;
            }
            tmrTableData.Enabled       = false;
            toolStripStatusLabel3.Text = "";

            // log history
            LogAction("StatusMesage", results.StatusMessage);
            LogAction("RowsReturned", (results.ResultsData != null ? "Returned " + results.ResultsData.Rows.Count + " rows" : "None"));
            if (results.ExceptionDetails != null)
            {
                foreach (DataGridViewRow row in dgrid_TableData.Rows)
                {
                    LogAction("Exception", row.Cells[0].Value + " : " + row.Cells[1].Value);
                }
            }
            dgrid_TableData.AutoResizeColumns();
            dgrid_TableData.AutoResizeRows();

            Cursor = Cursors.Default;
            btnApplyChangesToDB.Enabled = true;
        }