示例#1
0
        public static void update_database(DataTable dt, string table, string delete, string con_string)
        {
            if (dt != null)
            {
                try
                {
                    Function_Classes.execute_sql(delete, con_string);

                    using (var bulkCopy = new SqlBulkCopy(con_string, SqlBulkCopyOptions.KeepIdentity))
                    {
                        // my DataTable column names match my SQL Column names, so I simply made this loop. However if your column names don't match, just pass in which datatable name matches the SQL column name in Column Mappings
                        foreach (DataColumn col in dt.Columns)
                        {
                            bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
                        }

                        bulkCopy.BulkCopyTimeout      = 600;
                        bulkCopy.DestinationTableName = table;
                        bulkCopy.WriteToServer(dt);
                    }
                }
                catch (Exception ex)
                {
                    Common_Classes.send_message(ex.InnerException.ToString() + ": " + delete);
                }
            }
        }
        public static void write_error(Exception ex, string path)
        {
            DataTable dt = get_from_sql("SELECT * FROM dbo.ErrorLog WHERE 1 = 2", Variables.sparkline_con_string, false);
            DataRow   dr = dt.NewRow();

            dr["date_error"]       = DateTime.Now;
            dr["app_virtual_path"] = path;
            dr["error_msg"]        = ex.Message;
            dt.Rows.Add(dr);

            Common_Classes.update_database(dt, "dbo.ErrorLog", "DELETE FROM dbo.ErrorLog WHERE 1 = 2", Variables.sparkline_con_string);
        }