コード例 #1
0
        public static void ImportDataTableTest(MainForm frm)
        {
            PFDB2  db = new PFDB2();
            string connectionString = string.Empty;

            try
            {
                _msg.Length = 0;
                _msg.Append("ImportDataTableTest started ...");
                Program._messageLog.WriteLine(_msg.ToString());

                db.ServerName   = frm.txtServerName.Text;
                db.DatabaseName = frm.txtDatabaseName.Text;
                db.PortNumber   = frm.txtPortNumber.Text;
                db.Username     = frm.txtUsername.Text;
                db.Password     = frm.txtPassword.Text;

                connectionString = db.ConnectionString;



                db.OpenConnection();

                StringBuilder sql       = new StringBuilder();
                DataTable     dt        = frm.keyValsDataSet.Tables["Mike.KeyValTable"];
                string        tableName = dt.TableName;


                //first delete table if it already exists
                Program._messageLog.WriteLine("\r\nDropping old table if it exists ...");



                if (db.TableExists(tableName))
                {
                    bool dropped = db.DropTable(tableName);
                    if (dropped == false)
                    {
                        _msg.Length = 0;
                        _msg.Append("Unable to drop table ");
                        _msg.Append(tableName);
                        throw new DataException(_msg.ToString());
                    }
                }


                Program._messageLog.WriteLine("\r\nCreating a table in the database ...");

                //create the table
                db.CreateTable(dt);

                db.ImportDataFromDataTable(dt, 1000);

                db.CloseConnection();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("... ImportDataTableTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }