Example #1
0
        public void UploadTable(string connectionString, List <string> setupSql, Table tableInfo, DataTable uploadData, List <string> postSql)
        {
            string tempFile = Path.GetTempFileName() + ".csv";

            try
            {
                DsvConverter.WriteDatableDsv(uploadData, tempFile, BulkUploadDelimiter);

                using (var connection = new MySqlConnection(connectionString))
                {
                    connection.Open();
                    foreach (var sql in setupSql)
                    {
                        connection.Execute(sql);
                    }

                    BulkCopy(connection, tableInfo.temp_name, tempFile);

                    foreach (var sql in postSql)
                    {
                        connection.Execute(sql);
                    }
                }
            }
            finally
            {
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
Example #2
0
        public int BulkCopy(string connectionString, Table tableInfo, DataTable sourceTable)
        {
            string tempFile = Path.GetTempFileName() + ".csv";

            try
            {
                DsvConverter.WriteDatableDsv(sourceTable, tempFile, BulkUploadDelimiter);

                using (var connection = new MySqlConnection(connectionString))
                {
                    connection.Open();
                    var recordsCount = BulkCopy(connection, tableInfo.temp_name, tempFile);
                    return(recordsCount);
                }
            }
            finally
            {
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }