Setting PrimaryKey Column of table in dataset

  • Thread starter Thread starter Matt Tapia
  • Start date Start date
M

Matt Tapia

I have a dataset (dsAccounts) with one table. It has a column called
"strAccountNo" that I want to make the primary key. I use the following line
of code:

dsAccounts.Tables(0).PrimaryKey =
dsAccounts.Tables(0).Columns("strAccountNo")

but I get this error:

Value of type 'System.Data.DataColumn' cannot be converted to '1-dimensional
array of System.Data.DataColumn'.

Any suggestions?
 
Matt:
Matt Tapia said:
I have a dataset (dsAccounts) with one table. It has a column called
"strAccountNo" that I want to make the primary key. I use the following line
of code:

dsAccounts.Tables(0).PrimaryKey =
dsAccounts.Tables(0).Columns("strAccountNo")

but I get this error:

Value of type 'System.Data.DataColumn' cannot be converted to '1-dimensional
array of System.Data.DataColumn'.

Any suggestions?

Try this...

Dim dcArray() As DataColumn {dsAccounts.Tables(0).Columns("strAccountNo")}

dsAccounts.Tables(0).PrimaryKey = dcArray

The property PrimaryKey is an Array of DataColumns, you are setting it to a
column. If you create an array with only that field, you'll be good to go
(of course you can create a composite key if need be but that's another
issue).
 
Back
Top