DataColumn Constructores
Definición
Inicializa una nueva instancia de la clase DataColumn.Initializes a new instance of the DataColumn class.
Sobrecargas
DataColumn() |
Inicializa una nueva instancia de la clase DataColumn como cadena de tipo.Initializes a new instance of a DataColumn class as type string. |
DataColumn(String) |
Inicializa una nueva instancia de la clase DataColumn, como cadena de tipo, utilizando el nombre de columna especificado.Initializes a new instance of the DataColumn class, as type string, using the specified column name. |
DataColumn(String, Type) |
Inicializa una nueva instancia de la clase DataColumn con el nombre de columna y el tipo de datos especificados.Initializes a new instance of the DataColumn class using the specified column name and data type. |
DataColumn(String, Type, String) |
Inicializa una nueva instancia de la clase DataColumn con el nombre, el tipo de datos y la expresión especificados.Initializes a new instance of the DataColumn class using the specified name, data type, and expression. |
DataColumn(String, Type, String, MappingType) |
Inicializa una nueva instancia de la clase DataColumn con el nombre, el tipo de datos, la expresión y un valor que determina si la columna es un atributo; todos ellos especificados.Initializes a new instance of the DataColumn class using the specified name, data type, expression, and value that determines whether the column is an attribute. |
DataColumn()
Inicializa una nueva instancia de la clase DataColumn como cadena de tipo.Initializes a new instance of a DataColumn class as type string.
public:
DataColumn();
public DataColumn ();
Public Sub New ()
Ejemplos
En el ejemplo siguiente se crea un nuevo DataColumn , se establecen varias propiedades y se agrega a DataColumnCollection para el DataTable objeto.The following example creates a new DataColumn, sets various properties, and adds it to a DataColumnCollection for the DataTable object.
private void AddDataColumn(DataTable table)
{
DataColumn column = new DataColumn();
// Set various properties.
column.ColumnName = "id";
column.DataType = System.Type.GetType("System.Int32");
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
column.ReadOnly = true;
// Add to Columns collection.
table.Columns.Add(column);
}
Private Sub AddDataColumn(ByVal table As DataTable)
Dim column As New DataColumn()
' Set various properties.
With column
.ColumnName = "id"
.DataType = System.Type.GetType("System.Int32")
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
.ReadOnly = True
End With
' Add to Columns collection.
table.Columns.Add(column)
End Sub
Comentarios
Cuando se crea, un DataColumn objeto no tiene ningún valor predeterminado ColumnName o Caption .When created, a DataColumn object has no default ColumnName or Caption. Cuando se agrega a un DataColumnCollection , se generará un nombre predeterminado ("Column1", "columna2", etc.) si no se ha asignado un nombre a ColumnName .When you add it to a DataColumnCollection, a default name ("Column1", "Column2", and so on) will be generated if a name has not been assigned to the ColumnName.
Consulte también
- ColumnName
- Caption
- DefaultValue
- DataTable
- DataType
- Usar conjuntos de valores en ADO.NETUsing DataSets in ADO.NET
Se aplica a
DataColumn(String)
Inicializa una nueva instancia de la clase DataColumn, como cadena de tipo, utilizando el nombre de columna especificado.Initializes a new instance of the DataColumn class, as type string, using the specified column name.
public:
DataColumn(System::String ^ columnName);
public DataColumn (string? columnName);
public DataColumn (string columnName);
new System.Data.DataColumn : string -> System.Data.DataColumn
Public Sub New (columnName As String)
Parámetros
- columnName
- String
Cadena que representa el nombre de la columna que se va a crear.A string that represents the name of the column to be created. Si se establece en null
o en una cadena vacía (""), cuando se agregue a la colección de columnas se especificará un nombre predeterminado.If set to null
or an empty string (""), a default name will be specified when added to the columns collection.
Ejemplos
En el ejemplo siguiente se crea un nuevo DataColumn con un especificado ColumnName .The following example creates a new DataColumn with a specified ColumnName.
private void AddDataColumn(DataTable table)
{
DataColumn column = new DataColumn("id");
// Set various properties.
column.DataType = System.Type.GetType("System.Int32");
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
column.ReadOnly = true;
// Add to Columns collection.
table.Columns.Add(column);
}
Private Sub AddDataColumn(ByVal table As DataTable)
Dim column As DataColumn
column = New DataColumn("id")
' Set various properties.
With column
.DataType = System.Type.GetType("System.Int32")
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
.ReadOnly = True
End With
' Add to Columns collection.
table.Columns.Add(column)
End Sub
Comentarios
De forma predeterminada, el nombre específico de una columna se convierte en el Caption valor de propiedad.By default, the name specific to a column becomes the Caption property value.
Consulte también
- ColumnName
- Caption
- DefaultValue
- DataTable
- DataType
- Usar conjuntos de valores en ADO.NETUsing DataSets in ADO.NET
Se aplica a
DataColumn(String, Type)
Inicializa una nueva instancia de la clase DataColumn con el nombre de columna y el tipo de datos especificados.Initializes a new instance of the DataColumn class using the specified column name and data type.
public:
DataColumn(System::String ^ columnName, Type ^ dataType);
public DataColumn (string? columnName, Type dataType);
public DataColumn (string columnName, Type dataType);
new System.Data.DataColumn : string * Type -> System.Data.DataColumn
Public Sub New (columnName As String, dataType As Type)
Parámetros
- columnName
- String
Cadena que representa el nombre de la columna que se va a crear.A string that represents the name of the column to be created. Si se establece en null
o en una cadena vacía (""), cuando se agregue a la colección de columnas se especificará un nombre predeterminado.If set to null
or an empty string (""), a default name will be specified when added to the columns collection.
Excepciones
No se ha especificado ningún dataType
.No dataType
was specified.
Ejemplos
En el ejemplo siguiente se crea un nuevo DataColumn con un y un especificados ColumnName DataType .The following example creates a new DataColumn with a specified ColumnName and DataType.
private void AddDataColumn(DataTable table)
{
System.Type typeInt32 =
System.Type.GetType("System.Int32");
DataColumn column = new DataColumn("id", typeInt32);
// Set various properties.
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
column.ReadOnly = true;
// Add to Columns collection.
table.Columns.Add(column);
}
Private Sub AddDataColumn(ByVal table As DataTable)
Dim typeInt32 As System.Type = _
System.Type.GetType("System.Int32")
Dim column As DataColumn = _
New DataColumn("id", typeInt32)
' Set various properties.
With column
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
.ReadOnly = True
End With
' Add to Columns collection.
table.Columns.Add(column)
End Sub
Consulte también
- DefaultValue
- ColumnName
- Caption
- DataTable
- DataType
- Usar conjuntos de valores en ADO.NETUsing DataSets in ADO.NET
Se aplica a
DataColumn(String, Type, String)
Inicializa una nueva instancia de la clase DataColumn con el nombre, el tipo de datos y la expresión especificados.Initializes a new instance of the DataColumn class using the specified name, data type, and expression.
public:
DataColumn(System::String ^ columnName, Type ^ dataType, System::String ^ expr);
public DataColumn (string? columnName, Type dataType, string? expr);
public DataColumn (string columnName, Type dataType, string expr);
new System.Data.DataColumn : string * Type * string -> System.Data.DataColumn
Public Sub New (columnName As String, dataType As Type, expr As String)
Parámetros
- columnName
- String
Cadena que representa el nombre de la columna que se va a crear.A string that represents the name of the column to be created. Si se establece en null
o en una cadena vacía (""), cuando se agregue a la colección de columnas se especificará un nombre predeterminado.If set to null
or an empty string (""), a default name will be specified when added to the columns collection.
- expr
- String
Expresión utilizada para crear esta columna.The expression used to create this column. Para obtener más información, vea la propiedad Expression.For more information, see the Expression property.
Excepciones
No se ha especificado ningún dataType
.No dataType
was specified.
Ejemplos
En el ejemplo siguiente se crea una columna calculada.The following example creates a computed column.
private void AddDataColumn(DataTable table)
{
System.Type decimalType;
decimalType = System.Type.GetType("System.Decimal");
// Create the column. The name is 'Tax,' with data type Decimal,and
// an expression ('UnitPrice * .0862) to calculate the tax.
DataColumn column = new DataColumn("Tax",
decimalType, "UnitPrice * .0862");
// Set various properties.
column.AutoIncrement = false;
column.ReadOnly = true;
// Add to Columns collection.;
table.Columns.Add(column);
}
Private Sub AddDataColumn(ByVal table As DataTable)
Dim column As DataColumn
Dim decimalType As System.Type
decimalType = System.Type.GetType("System.Decimal")
column = New DataColumn("Tax", decimalType, "UnitPrice * .0862")
' Set various properties.
With column
.AutoIncrement = False
.ReadOnly = True
End With
' Add to Columns collection.
table.Columns.Add(column)
End Sub
Consulte también
- DefaultValue
- ColumnName
- Caption
- DataTable
- DataType
- Expression
- Usar conjuntos de valores en ADO.NETUsing DataSets in ADO.NET
Se aplica a
DataColumn(String, Type, String, MappingType)
Inicializa una nueva instancia de la clase DataColumn con el nombre, el tipo de datos, la expresión y un valor que determina si la columna es un atributo; todos ellos especificados.Initializes a new instance of the DataColumn class using the specified name, data type, expression, and value that determines whether the column is an attribute.
public:
DataColumn(System::String ^ columnName, Type ^ dataType, System::String ^ expr, System::Data::MappingType type);
public DataColumn (string? columnName, Type dataType, string? expr, System.Data.MappingType type);
public DataColumn (string columnName, Type dataType, string expr, System.Data.MappingType type);
new System.Data.DataColumn : string * Type * string * System.Data.MappingType -> System.Data.DataColumn
Public Sub New (columnName As String, dataType As Type, expr As String, type As MappingType)
Parámetros
- columnName
- String
Cadena que representa el nombre de la columna que se va a crear.A string that represents the name of the column to be created. Si se establece en null
o en una cadena vacía (""), cuando se agregue a la colección de columnas se especificará un nombre predeterminado.If set to null
or an empty string (""), a default name will be specified when added to the columns collection.
- expr
- String
Expresión utilizada para crear esta columna.The expression used to create this column. Para obtener más información, vea la propiedad Expression.For more information, see the Expression property.
- type
- MappingType
Uno de los valores de MappingType.One of the MappingType values.
Excepciones
No se ha especificado ningún dataType
.No dataType
was specified.
Ejemplos
En el ejemplo siguiente se crea una columna calculada.The following example constructs a computed column.
private void CreateComputedColumn(DataTable table)
{
System.Type myDataType =
System.Type.GetType("System.Decimal");
// The expression multiplies the "Price" column value
// by the "Quantity" to create the "Total" column.
string expression = "Price * Quantity";
// Create the column, setting the type to Attribute.
DataColumn column = new DataColumn("Total", myDataType,
expression, MappingType.Attribute);
// Set various properties.
column.AutoIncrement = false;
column.ReadOnly = true;
// Add the column to a DataTable object's to DataColumnCollection.
DataSet1.Tables["OrderDetails"].Columns.Add(column);
}
Private Sub CreateComputedColumn(ByVal table As DataTable)
Dim column As DataColumn
Dim decimalType As System.Type = _
System.Type.GetType("System.Decimal")
' The expression multiplies the "Price" column value by the
' "Quantity" to create the "Total" column.
Dim expression As String = "Price * Quantity"
' Create the column, setting the type to Attribute.
column = New DataColumn("Total", decimalType, _
expression, MappingType.Attribute)
' Set various properties.
column.AutoIncrement = False
column.ReadOnly = True
' Add the column to a DataTable object's DataColumnCollection.
DataSet1.Tables("OrderDetails").Columns.Add(column)
End Sub
Comentarios
El type
argumento establece la ColumnMapping propiedad.The type
argument sets the ColumnMapping property. La propiedad especifica cómo DataColumn se asigna un cuando DataSet se transforma en un documento XML.The property specifies how a DataColumn is mapped when a DataSet is transformed into an XML document. Por ejemplo, si la columna se denomina "fName" y el valor que contiene es "Bob", y type
está establecido en MappingType.Attribute
, el elemento XML sería como sigue:For example, if the column is named "fName," and the value it contains is "Bob," and type
is set to MappingType.Attribute
, the XML element would be as follows:
<Name fName = 'Bob'/>
Para obtener más información sobre cómo se asignan las columnas a elementos o atributos, vea la ColumnMapping propiedad.For more information about how columns are mapped to elements or attributes, see the ColumnMapping property.
Consulte también
- ColumnName
- ColumnMapping
- Caption
- DefaultValue
- DataTable
- DataType
- Usar conjuntos de valores en ADO.NETUsing DataSets in ADO.NET