Exemple #1
0
        public static void ImportDataTableTest()
        {
            PFSybase db = new PFSybase();
            string   connectionString = string.Empty;

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

                db.ServerName   = _frm.txtServerName.Text;
                db.Port         = _frm.txtPort.Text;
                db.DatabaseName = _frm.txtDatabaseName.Text;
                db.Username     = _frm.txtUsername.Text;
                db.Password     = _frm.txtPassword.Text;

                connectionString = db.ConnectionString;



                db.OpenConnection();

                StringBuilder sql = new StringBuilder();


                //first delete table if it already exists
                string schemaName = "dbo";
                string tabName    = "KeyValTable";


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



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

                //create the table

                DataTable dt = _frm.keyValsDataSet.Tables["dbo.KeyValTable"];

                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());
            }
        }