Beispiel #1
0
        public static void ImportDataTableTest(MainForm frm)
        {
            PFSQLServerCE40 db               = new PFSQLServerCE40();
            string          fileName         = @"c:\temp\AppSettings_40.sdf";
            string          dataSource       = fileName;
            string          connectionString = string.Empty;
            string          createScript     = string.Empty;

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

                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                db.DatabasePath  = dataSource;
                connectionString = db.ConnectionString;

                //create the database
                bool dbCreated = db.CreateDatabase(connectionString);
                if (dbCreated == false)
                {
                    _msg.Length = 0;
                    _msg.Append("Attempt to create database ");
                    _msg.Append(fileName);
                    _msg.Append(" failed.");
                    throw new DataException(_msg.ToString());
                }

                db.OpenConnection();

                //create the table
                DataTable dt = frm.keyValsDataSet.Tables["KeyValTable"];
                db.CreateTable(dt);

                db.ImportDataFromDataTable(dt);

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