Can I do this on One line of code?

  • Thread starter Thread starter gregory_may
  • Start date Start date
G

gregory_may

Seems silly I need two lines of code for this. Any way to do it in one?



Dim DcArray() As DataColumn = {MyData.Tables(0).Columns("PhoneNumber")}

MyData.Tables(0).PrimaryKey = DcArray
 
gregory_may said:
Seems silly I need two lines of code for this. Any way to do it in one?



Dim DcArray() As DataColumn = {MyData.Tables(0).Columns("PhoneNumber")}

MyData.Tables(0).PrimaryKey = DcArray


mydata.Tables(0).PrimaryKey = New DataColumn()
{mydata.Tables(0).Columns("PhoneNumber")}

Two lines only due to word wrapping in the posting. :) Usually I would write

mydata.Tables(0).PrimaryKey = New DataColumn() { _
mydata.Tables(0).Columns("PhoneNumber") _
}

but than you had three lines instead of one.... Therefore I would change it
to

Dim DcArray() As DataColumn = {MyData.Tables(0).Columns("PhoneNumber")}

MyData.Tables(0).PrimaryKey = DcArray


Ooops, that's what you already have.

;-)


Armin
 
gregory_may said:
Seems silly I need two lines of code for this. > Dim DcArray() As
DataColumn = {MyData.Tables(0).Columns("PhoneNumber")}
MyData.Tables(0).PrimaryKey = DcArray
Any way to do it in one?

Haven't tried it, but does this work?

With MyData.Tables(0)
.PrimaryKey _
= New DataColumn() { .Columns("PhoneNumber") }
End With

HTH,
Phill W.
 
MyData.Tables(0).PrimaryKey = New DataColumn()
{MyData.Tables(0).Columns("PhoneNumber")}
 
Thanks guys, the New DataColumn() {} syntax is what I was after.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top