Home All Groups Group Topic Archive Search About

Get error when try to set DataColumn variable again

Author
16 May 2006 6:29 PM
Christopher Lusardi
On the second call to the below method body, I get the error: A column
named 'Full Name' already belongs to this Data Table. In C++, what I
would do is either set col to null on exit from the method, or only do
the assignment if col is emply. Explicitly, how would I do these 2
things in VB?

Dim col As DataColumn

col = dsAdoSbs.Employees.Columns.Add("FullName",
System.Type.GetType("System.String"))

Thanks,
Christopher Lusardi

Author
16 May 2006 7:04 PM
tomb
Christopher Lusardi wrote:

Show quoteHide quote
>On the second call to the below method body, I get the error: A column
>named 'Full Name' already belongs to this Data Table. In C++, what I
>would do is either set col to null on exit from the method, or only do
>the assignment if col is emply. Explicitly, how would I do these 2
>things in VB?
>
>Dim col As DataColumn
>
>col = dsAdoSbs.Employees.Columns.Add("FullName",
>System.Type.GetType("System.String"))
>
>Thanks,
>Christopher Lusardi
>

>
Try deleting the column.  Then you can add it again later.

T
Author
17 May 2006 8:38 AM
Cor Ligthert [MVP]
Christopher,

There exist in Net the command "Add" and "Remove" column.

A pity is that you can save the column,

dim mycolumn as datatable.column = mydatatable.column(0)

but that does not contain the values in the items.

I hope this helps,

Cor

Show quoteHide quote
"Christopher Lusardi" <clusard***@aol.com> schreef in bericht
news:1147804182.844818.36580@j55g2000cwa.googlegroups.com...
> On the second call to the below method body, I get the error: A column
> named 'Full Name' already belongs to this Data Table. In C++, what I
> would do is either set col to null on exit from the method, or only do
> the assignment if col is emply. Explicitly, how would I do these 2
> things in VB?
>
> Dim col As DataColumn
>
> col = dsAdoSbs.Employees.Columns.Add("FullName",
> System.Type.GetType("System.String"))
>
> Thanks,
> Christopher Lusardi
>