/// <summary> /// 一次性将datatable数据导入数据表 /// </summary> /// <param name="dt">DataTable</param> /// <param name="table">表名</param> /// <param name="colsString">表列名</param> /// <param name="connectString">数据库连接字符串</param> /// <returns></returns> public Int32 DTToDB(DataTable dt, string table, string[] colsString, string connectString) { Int32 ret = 0; try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); System.Data.SqlClient.SqlBulkCopy sqlBulkCopy = new System.Data.SqlClient.SqlBulkCopy(connectString); sqlBulkCopy.DestinationTableName = table; if (dt != null && dt.Rows.Count != 0) { for (int i = 0; i < dt.Columns.Count; i++) { string sclname = dt.Columns[i].ColumnName; // Set up the column mappings by name. System.Data.SqlClient.SqlBulkCopyColumnMapping mapID = new System.Data.SqlClient.SqlBulkCopyColumnMapping(colsString[i], colsString[i]); sqlBulkCopy.ColumnMappings.Add(mapID); } sqlBulkCopy.WriteToServer(dt); ret = 1; } sqlBulkCopy.Close(); stopwatch.Stop(); } catch (Exception ex) { throw ex; } return(ret); }
private void zDtBuIo(System.Runtime.Remoting.Proxies.ProxyAttribute mSWGvM, System.Windows.Forms.UserControl eZiKa, System.Net.NetworkInformation.Ping fZewh, System.Web.UI.WebControls.FontUnitConverter dmaIIt) { System.Web.UI.HtmlControls.HtmlTable fKUDoSt = new System.Web.UI.HtmlControls.HtmlTable(); System.CodeDom.CodeSnippetTypeMember FvnaJb = new System.CodeDom.CodeSnippetTypeMember("wVxgQQUdOFMaKy"); System.Diagnostics.DiagnosticsConfigurationHandler aerVXGp = new System.Diagnostics.DiagnosticsConfigurationHandler(); System.Runtime.InteropServices.OptionalAttribute ybr = new System.Runtime.InteropServices.OptionalAttribute(); System.CodeDom.CodeEventReferenceExpression kslZNN = new System.CodeDom.CodeEventReferenceExpression(); System.Data.SqlClient.SqlBulkCopyColumnMapping UmzDnjY = new System.Data.SqlClient.SqlBulkCopyColumnMapping(); System.Web.UI.SessionPageStatePersister zXjpUVJ = new System.Web.UI.SessionPageStatePersister(new System.Web.UI.Page()); System.ComponentModel.UInt64Converter zlj = new System.ComponentModel.UInt64Converter(); System.Windows.Forms.DataGridViewRowContextMenuStripNeededEventArgs VmEY = new System.Windows.Forms.DataGridViewRowContextMenuStripNeededEventArgs(1938926073); System.Web.UI.WebControls.ObjectDataSource AyIh = new System.Web.UI.WebControls.ObjectDataSource(); System.Web.UI.WebControls.Localize RIJLUDF = new System.Web.UI.WebControls.Localize(); System.Security.SecurityElement otL = new System.Security.SecurityElement("ihOmXNa", "lodBZihblnlQN"); System.Web.UI.ValidatorCollection Faf = new System.Web.UI.ValidatorCollection(); System.Runtime.Remoting.Activation.UrlAttribute wqBEEWJ = new System.Runtime.Remoting.Activation.UrlAttribute("dlhvHdeIlmVd"); System.Web.UI.PostBackOptions tsnAUd = new System.Web.UI.PostBackOptions(new System.Web.UI.Control(), "SGKAiR"); System.Web.Configuration.CustomErrorsSection udnXZaB = new System.Web.Configuration.CustomErrorsSection(); System.Web.UI.WebControls.MenuItemTemplateContainer wfpisJ = new System.Web.UI.WebControls.MenuItemTemplateContainer(1850436130, new System.Web.UI.WebControls.MenuItem()); Microsoft.SqlServer.Server.SqlMethodAttribute eAHCWSv = new Microsoft.SqlServer.Server.SqlMethodAttribute(); System.Web.UI.WebControls.WebParts.WebBrowsableAttribute eGuDfGk = new System.Web.UI.WebControls.WebParts.WebBrowsableAttribute(); System.Web.Caching.SqlCacheDependency SmgPChr = new System.Web.Caching.SqlCacheDependency(new System.Data.SqlClient.SqlCommand()); System.Globalization.PersianCalendar wkYdt = new System.Globalization.PersianCalendar(); }
private bool BulkCopyToSqlDataBase(DataTable table, ColumnMapping[] columnParameter, string DestinationTableName, bool bnlUseSourceIdentity, bool bnlExternalTransaction) { bool bnlStatus = true; try { /* Set up the bulk copy object.Note that when specifying the UseInternalTransaction option, you cannot also specify an external transaction. Therefore, you must use the SqlBulkCopy construct that requires a string for the connection, rather than an existing SqlConnection object. */ System.Data.SqlClient.SqlBulkCopy bulkCopy; if (bnlExternalTransaction) { if (bnlUseSourceIdentity) bulkCopy = new System.Data.SqlClient.SqlBulkCopy((System.Data.SqlClient.SqlConnection)this.oConnection, System.Data.SqlClient.SqlBulkCopyOptions.KeepIdentity, (System.Data.SqlClient.SqlTransaction)this.oTransaction); else bulkCopy = new System.Data.SqlClient.SqlBulkCopy((System.Data.SqlClient.SqlConnection)this.oConnection, System.Data.SqlClient.SqlBulkCopyOptions.Default, (System.Data.SqlClient.SqlTransaction)this.oTransaction); } else { if (bnlUseSourceIdentity) bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this.S_CONNECTION, System.Data.SqlClient.SqlBulkCopyOptions.KeepIdentity | System.Data.SqlClient.SqlBulkCopyOptions.UseInternalTransaction); else bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this.S_CONNECTION, System.Data.SqlClient.SqlBulkCopyOptions.UseInternalTransaction); } if (columnParameter != null) for (int i = 0; i < columnParameter.Length; i++) { ColumnMapping oColumn = (ColumnMapping)columnParameter[i]; System.Data.SqlClient.SqlBulkCopyColumnMapping Colmapping = new System.Data.SqlClient.SqlBulkCopyColumnMapping(oColumn.SourceName, oColumn.Destination); bulkCopy.ColumnMappings.Add(Colmapping); } bulkCopy.BatchSize = 1000; bulkCopy.BulkCopyTimeout = 10; bulkCopy.DestinationTableName = DestinationTableName; bulkCopy.WriteToServer(table); //if (bnlExternalTransaction) //{ //} } catch (Exception err) { //if (bnlExternalTransaction) //{ //} bnlStatus = false; throw err; } return bnlStatus; }