0

我希望能够传递一个或多个作为列名的字符串。然后,该方法会将这些列设置为主键。

代码进行中

public sub setPK(ParamArray columnNames As String())
    Dim primaryKeyColumns As List(Of System.Data.DataColumn)
    For Each s As String In columnNames
        primaryKeyColumns.Add(dataTable.Columns(s))
    Next
    dataTable.PrimaryKey = New System.Data.DataColumn() {primaryKeyColumns}
End Sub

我将不胜感激任何帮助/建议。

4

1 回答 1

0
Public Sub setPK(ParamArray columnNames As String())
    Dim primaryKeyColumns(columnNames.Count - 1) As System.Data.DataColumn
    For i As Integer = 0 To columnNames.Count - 1 Step 1
        primaryKeyColumns(i) = dataTable.Columns(columnNames(i))
    Next
    dataTable.PrimaryKey = primaryKeyColumns
End Sub
于 2013-07-27T23:00:50.100 回答