SqlBulkCopyColumnMapping.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //------------------------------------------------------------------------------
  2. // <copyright file="SqlBulkCopyColumnMapping.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">[....]</owner>
  6. // <owner current="true" primary="false">[....]</owner>
  7. //------------------------------------------------------------------------------
  8. // Todo: rename the file
  9. // Caution! ndp\fx\src\data\netmodule\sources needs to follow this change
  10. namespace System.Data.SqlClient
  11. {
  12. using System;
  13. using System.Data;
  14. using System.Data.Common;
  15. using System.Data.SqlTypes;
  16. using System.ComponentModel;
  17. using System.Collections;
  18. using System.Diagnostics;
  19. // -------------------------------------------------------------------------------------------------
  20. // this class helps allows the user to create association between source- and targetcolumns
  21. //
  22. //
  23. public sealed class SqlBulkCopyColumnMapping {
  24. internal string _destinationColumnName;
  25. internal int _destinationColumnOrdinal;
  26. internal string _sourceColumnName;
  27. internal int _sourceColumnOrdinal;
  28. // devnote: we don't want the user to detect the columnordinal after WriteToServer call.
  29. // _sourceColumnOrdinal(s) will be copied to _internalSourceColumnOrdinal when WriteToServer executes.
  30. internal int _internalDestinationColumnOrdinal;
  31. internal int _internalSourceColumnOrdinal; // -1 indicates an undetermined value
  32. public string DestinationColumn {
  33. get {
  34. if (_destinationColumnName != null) {
  35. return _destinationColumnName;
  36. }
  37. return string.Empty;
  38. }
  39. set {
  40. _destinationColumnOrdinal = _internalDestinationColumnOrdinal = -1;
  41. _destinationColumnName = value;
  42. }
  43. }
  44. public int DestinationOrdinal {
  45. get {
  46. return _destinationColumnOrdinal;
  47. }
  48. set {
  49. if (value >= 0) {
  50. _destinationColumnName = null;
  51. _destinationColumnOrdinal = _internalDestinationColumnOrdinal = value;
  52. }
  53. else {
  54. throw ADP.IndexOutOfRange(value);
  55. }
  56. }
  57. }
  58. public string SourceColumn {
  59. get {
  60. if (_sourceColumnName != null) {
  61. return _sourceColumnName;
  62. }
  63. return string.Empty;
  64. }
  65. set {
  66. _sourceColumnOrdinal = _internalSourceColumnOrdinal = -1;
  67. _sourceColumnName = value;
  68. }
  69. }
  70. public int SourceOrdinal {
  71. get {
  72. return _sourceColumnOrdinal;
  73. }
  74. set {
  75. if (value >= 0) {
  76. _sourceColumnName = null;
  77. _sourceColumnOrdinal = _internalSourceColumnOrdinal = value;
  78. }
  79. else {
  80. throw ADP.IndexOutOfRange(value);
  81. }
  82. }
  83. }
  84. public SqlBulkCopyColumnMapping () {
  85. _internalSourceColumnOrdinal = -1;
  86. }
  87. public SqlBulkCopyColumnMapping (string sourceColumn, string destinationColumn) {
  88. SourceColumn = sourceColumn;
  89. DestinationColumn = destinationColumn;
  90. }
  91. public SqlBulkCopyColumnMapping (int sourceColumnOrdinal, string destinationColumn) {
  92. SourceOrdinal = sourceColumnOrdinal;
  93. DestinationColumn = destinationColumn;
  94. }
  95. public SqlBulkCopyColumnMapping (string sourceColumn, int destinationOrdinal) {
  96. SourceColumn = sourceColumn;
  97. DestinationOrdinal = destinationOrdinal;
  98. }
  99. public SqlBulkCopyColumnMapping (int sourceColumnOrdinal, int destinationOrdinal) {
  100. SourceOrdinal = sourceColumnOrdinal;
  101. DestinationOrdinal = destinationOrdinal;
  102. }
  103. }
  104. }