2 // System.Data.DataColumn.cs
5 // Christopher Podurgiel (cpodurgiel@msn.com)
6 // Rodrigo Moya (rodrigo@ximian.com)
7 // Daniel Morgan (danmorg@sc.rr.com)
10 // (C) Ximian, Inc 2002
15 using System.ComponentModel;
20 /// Summary description for DataColumn.
22 public class DataColumn : MarshalByValueComponent
26 private bool allowDBNull = true;
27 private bool autoIncrement = false;
28 private long autoIncrementSeed = 0;
29 private long autoIncrementStep = 1;
30 private string caption = null;
31 private MappingType columnMapping = MappingType.Element;
32 private string columnName = null;
33 private Type dataType = null;
34 private object defaultValue = null;
35 private string expression = null;
36 private PropertyCollection extendedProperties = null;
37 private int maxLength = -1;
38 private string nameSpace = null;
39 private int ordinal = -1;
40 private string prefix = null;
41 private bool readOnly = false;
42 private DataTable _table = null;
43 private bool unique = false;
53 public DataColumn(string columnName): this()
55 ColumnName = columnName;
58 public DataColumn(string columnName, Type dataType): this(columnName)
60 if(dataType == null) {
61 throw new ArgumentNullException();
68 public DataColumn( string columnName, Type dataType,
69 string expr): this(columnName, dataType)
74 public DataColumn(string columnName, Type dataType,
75 string expr, MappingType type): this(columnName, dataType, expr)
83 public bool AllowDBNull
94 /// Gets or sets a value indicating whether the column automatically increments the value of the column for new rows added to the table.
97 /// If the type of this column is not Int16, Int32, or Int64 when this property is set,
98 /// the DataType property is coerced to Int32. An exception is generated if this is a computed column
99 /// (that is, the Expression property is set.) The incremented value is used only if the row's value for this column,
100 /// when added to the columns collection, is equal to the default value.
102 public bool AutoIncrement
105 return autoIncrement;
108 autoIncrement = value;
109 if(autoIncrement == true)
111 if(Expression != null)
113 throw new Exception();
115 if(Type.GetTypeCode(dataType) != TypeCode.Int16 &&
116 Type.GetTypeCode(dataType) != TypeCode.Int32 &&
117 Type.GetTypeCode(dataType) != TypeCode.Int64)
119 Int32 dtInt = new Int32();
120 dataType = dtInt.GetType();
126 public long AutoIncrementSeed
129 return autoIncrementSeed;
132 autoIncrementSeed = value;
136 public long AutoIncrementStep
139 return autoIncrementStep;
142 autoIncrementStep = value;
146 public string Caption
159 public virtual MappingType ColumnMapping
162 return columnMapping;
165 columnMapping = value;
169 public string ColumnName
185 if(AutoIncrement == true &&
186 Type.GetTypeCode(value) != TypeCode.Int32)
188 throw new Exception();
197 /// <remarks>When AutoIncrement is set to true, there can be no default value.</remarks>
198 public object DefaultValue
204 defaultValue = value;
208 public string Expression
218 public PropertyCollection ExtendedProperties
221 return extendedProperties;
235 public string Namespace
245 //Need a good way to set the Ordinal when the column is added to a columnCollection.
273 public DataTable Table
290 #endregion // Properties
295 protected internal void CheckNotAllowNull() {
299 protected void CheckUnique() {
303 protected internal virtual void
304 OnPropertyChanging (PropertyChangedEventArgs pcevent) {
308 protected internal void RaisePropertyChanging(string name) {
312 /// Gets the Expression of the column, if one exists.
314 /// <returns>The Expression value, if the property is set;
315 /// otherwise, the ColumnName property.</returns>
317 public override string ToString()
319 if (expression != null)
326 internal void SetTable(DataTable table) {
328 // FIXME: this will get called by DataTable
329 // and DataColumnCollection
332 #endregion // Methods