我希望能够传递一个或多个列名称的字符串。然后,该方法将这些列设置为主键。
代码正在进行中
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
我将不胜感激任何帮助/建议。
答案 0 :(得分: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