DataTableMappingCollection.Add 方法
定义
将 DataTableMapping 对象添加到集合中。Adds a DataTableMapping object to the collection.
重载
| Add(Object) |
添加 Object,它是集合的表映射。Adds an Object that is a table mapping to the collection. |
| Add(String, String) |
给定源表名称和 DataSet 表名时,向集合添加 DataTableMapping 对象。Adds a DataTableMapping object to the collection when given a source table name and a DataSet table name. |
Add(Object)
public:
virtual int Add(System::Object ^ value);
public int Add (object? value);
public int Add (object value);
abstract member Add : obj -> int
override this.Add : obj -> int
Public Function Add (value As Object) As Integer
参数
- value
- Object
要添加到集合的 DataTableMapping 对象。A DataTableMapping object to add to the collection.
返回
添加到集合中的 DataTableMapping 对象的索引。The index of the DataTableMapping object added to the collection.
实现
例外
传入的对象不是 DataTableMapping 对象。The object passed in was not a DataTableMapping object.
示例
下面的示例搜索 DataTableMapping 集合中的。The following example searches for a DataTableMapping within the collection. 如果集合中存在该映射,则将其删除。If the mapping exists in the collection, it is removed. 如果集合中不存在映射,则会将其添加到集合中,并显示其索引。If the mapping does not exist within the collection, it is added to the collection and its index is displayed. 该示例假设 DataTableMappingCollection 已创建一个集合和一个 DataTableMapping 对象。The example assumes that a DataTableMappingCollection collection and a DataTableMapping object have been created.
public void ChangedMyMind()
{
// ...
// create mappings and mapping
// ...
if (mappings.Contains((Object) mapping))
{
mappings.Remove((Object) mapping);
}
else
{
mappings.Add((Object) mapping);
Console.WriteLine("Index of new mapping: "
+ mappings.IndexOf((Object) mapping));
}
}
Public Sub ChangedMyMind()
' ...
' create mappings and mapping
' ...
If mappings.Contains(CType(mapping, Object)) Then
mappings.Remove(CType(mapping, Object))
Else
mappings.Add(CType(mapping, Object))
Console.WriteLine("Index of new mapping: " _
+ mappings.IndexOf(CType(mapping, Object)).ToString())
End If
End Sub
适用于
Add(String, String)
给定源表名称和 DataSet 表名时,向集合添加 DataTableMapping 对象。Adds a DataTableMapping object to the collection when given a source table name and a DataSet table name.
public:
System::Data::Common::DataTableMapping ^ Add(System::String ^ sourceTable, System::String ^ dataSetTable);
public System.Data.Common.DataTableMapping Add (string? sourceTable, string? dataSetTable);
public System.Data.Common.DataTableMapping Add (string sourceTable, string dataSetTable);
member this.Add : string * string -> System.Data.Common.DataTableMapping
Public Function Add (sourceTable As String, dataSetTable As String) As DataTableMapping
参数
- sourceTable
- String
要从中映射的源表的区分大小写的名称。The case-sensitive name of the source table to map from.
- dataSetTable
- String
要映射到的 DataSet 表的名称(该名称不区分大小写)。The name, which is not case-sensitive, of the DataSet table to map to.
返回
已添加到集合中的 DataTableMapping 对象。The DataTableMapping object that was added to the collection.
示例
下面的示例创建一个 DataTableMappingCollection ,将 DataTableMapping 对象添加到集合,并显示映射的源表的列表。The following example creates a DataTableMappingCollection, adds DataTableMapping objects to the collection, and displays a list of the mapped source tables.
public void CreateTableMappings()
{
DataTableMappingCollection mappings =
new DataTableMappingCollection();
mappings.Add("Categories","DataCategories");
mappings.Add("Orders","DataOrders");
mappings.Add("Products","DataProducts");
string message = "TableMappings:\n";
for(int i=0;i < mappings.Count;i++)
{
message += i.ToString() + " "
+ mappings[i].ToString() + "\n";
}
Console.WriteLine(message);
}
Public Sub CreateTableMappings()
Dim mappings As New DataTableMappingCollection()
mappings.Add("Categories", "DataCategories")
mappings.Add("Orders", "DataOrders")
mappings.Add("Products", "DataProducts")
Dim message As String = "TableMappings:" & ControlChars.Cr
Dim i As Integer
For i = 0 To mappings.Count - 1
message &= i.ToString() & " " + mappings(i).ToString() _
& ControlChars.Cr
Next i
Console.WriteLine(message)
End Sub