Home All Groups Group Topic Archive Search About

Can I do this on One line of code?

Author
19 Jan 2006 12:12 AM
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

Author
19 Jan 2006 12:40 AM
Armin Zingler
"gregory_may" <None> schrieb
> 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
Author
19 Jan 2006 5:47 AM
Cor Ligthert [MVP]
Gregory,

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

Cor
Author
19 Jan 2006 8:59 AM
Phill W.
"gregory_may" <None> wrote in message
news:O8ZkIqIHGHA.240@TK2MSFTNGP11.phx.gbl...
> 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.
Author
19 Jan 2006 10:10 AM
Stephany Young
MyData.Tables(0).PrimaryKey = New DataColumn()
{MyData.Tables(0).Columns("PhoneNumber")}


Show quoteHide quote
"gregory_may" <None> wrote in message
news:O8ZkIqIHGHA.240@TK2MSFTNGP11.phx.gbl...
> 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
>
>
>
Author
19 Jan 2006 5:33 PM
gregory_may
Thanks guys, the New DataColumn() {} syntax is what I was after.

Thanks!

Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:%23tCOjCOHGHA.140@TK2MSFTNGP12.phx.gbl...
> MyData.Tables(0).PrimaryKey = New DataColumn()
> {MyData.Tables(0).Columns("PhoneNumber")}
>
>
> "gregory_may" <None> wrote in message
> news:O8ZkIqIHGHA.240@TK2MSFTNGP11.phx.gbl...
>> 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
>>
>>
>>
>
>