Beispiel #1
0
        public static void GetQueryDataSchema(MainForm frm)
        {
            PFOdbc db = new PFOdbc();

            Program._messageLog.WriteLine("GetQueryDataSchema started ...");
            try
            {
                db.ConnectionString = frm.cboConnectionString.Text;
                db.OpenConnection();

                _msg.Length = 0;
                _msg.Append("Connection string is ");
                _msg.Append(db.ConnectionString);
                _msg.Append("\r\n");
                _msg.Append("Connection state is  ");
                _msg.Append(db.Connection.State.ToString());
                _msg.Append("\r\n");
                _msg.Append("Query text is:\r\n");
                _msg.Append(frm.txtSqlQuery.Text.ToString());
                Program._messageLog.WriteLine(_msg.ToString());

                db.SQLQuery    = frm.txtSqlQuery.Text;
                db.CommandType = CommandType.Text;

                DataTable tab = db.GetQueryDataSchema();
                foreach (DataColumn col in tab.Columns)
                {
                    _msg.Length = 0;
                    _msg.Append(col.ColumnName);
                    _msg.Append(", ");
                    _msg.Append(col.DataType.ToString());
                    Program._messageLog.WriteLine(_msg.ToString());
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                if (db.Connection.State == ConnectionState.Open)
                {
                    db.CloseConnection();
                }
                Program._messageLog.WriteLine("... GetQueryDataSchema finished.");
            }
        }