PC Review


Reply
Thread Tools Rate Thread

Can't understand why code saying column doesn't belong to DataTable

 
 
Ronald S. Cook
Guest
Posts: n/a
 
      19th Feb 2007
In the code below, I get a runtime error where indicated. The error is:

"Column 'TICKETNO' does not belong to table TICKET_DEDUCTIONS."

If I put a breakpoint on that line (so not yet executed) and type
?dedrow(c), It says basically the same thing:

Run-time exception thrown : System.ArgumentException - Column 'TICKETNO'
does not belong to table TICKET_DEDUCTIONS.

But if I type ?dedrow. the intellisense does show that TICKETNO is a
property.

Does anything jump out at anybody as being blatantly wrong?

Thanks,
Ron

Here is the code:

For Each dedrow In dsdeductions.TICKET_DEDUCTIONS
If dedrow(7, DataRowVersion.Original) = drow.cntID Then
If dedrow.RowState <> DataRowState.Added Then
ndedrow = DsPurchaseReceiver1.TICKET_DEDUCTIONS.NewRow
For Each c In DsPurchaseReceiver1.TICKET_DEDUCTIONS.Columns
If c.ColumnName <> "cntID" Then
ndedrow(c) = dedrow(c, DataRowVersion.Original) <<<---- ERRORS
HERE
End If
Next
ndedrow.RecDetailsID = ndrow.cntID
DsPurchaseReceiver1.TICKET_DEDUCTIONS.AddTICKET_DEDUCTIONSRow(ndedrow)
End If
End If
Next







 
Reply With Quote
 
 
 
 
RobinS
Guest
Posts: n/a
 
      20th Feb 2007
First, you need to turn Option Strict On if you don't already have it
turned on. The reason I think you don't is because of this loop:

> For Each c In DsPurchaseReceiver1.TICKET_DEDUCTIONS.Columns
> If c.ColumnName <> "cntID" Then
> ndedrow(c) = dedrow(c, DataRowVersion.Original) <<<---- ERRORS
> > End If

> Next


What is "c" ? If it's a column in
DSPurchaseReceiver1.Ticket_Deductions.Columns, it should be defined as
such. Is it defined elsewhere in the program?

You can set OptionStrictOn at the top of your routine, but it's recommended
in VB that you set it in the default project properties and always use it.
This keeps you from having weird problems where VB is trying to guess what
type to convert to in order to use a variable that is not defined
correctly.

Try it and see what problems it reveals.

For example, is dedrow(7) the same data type as drow.cntID?

> If dedrow(7, DataRowVersion.Original) = drow.cntID Then


I can't tell what type some of your variables are, so if you re-post,
please be more generous in your information, as that might be what's
causing your problem.

I tried your method using Northwind, and it works fine, as displayed here.

Dim ds As NorthwindDataSet = New NorthwindDataSet()
Dim custAdapter As CustomersTableAdapter = New CustomersTableAdapter()
custAdapter.Fill(ds.Customers)

Dim rw As NorthwindDataSet.CustomersRow = _
DirectCast(ds.Customers.Rows(0), NorthwindDataSet.CustomersRow)
'change one value
rw.PostalCode = "9999"
'verify that it's got it
Console.WriteLine("rw.DataRowVersion.Original = {0}, " & _
" rw.DataRowVersion.Current = {1}", _
rw.Item("PostalCode", DataRowVersion.Original), _
rw.Item("PostalCode", DataRowVersion.Current))

'move the data from rw to nrw.
Dim nrw As NorthwindDataSet.CustomersRow = _
DirectCast(ds.Customers.NewRow(), NorthwindDataSet.CustomersRow)

For Each c As DataColumn In ds.Customers.Columns
nrw(c) = rw(c, DataRowVersion.Original)
Next

'show the new value in the old column
' and the proposed value in the nrw row
For Each c As DataColumn In ds.Customers.Columns
Console.WriteLine("rw." & c.ColumnName & " = " & _
rw(c, DataRowVersion.Current).ToString & _
" nrw = " & nrw.Item(c, DataRowVersion.Proposed).ToString)
Next


Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
"Ronald S. Cook" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In the code below, I get a runtime error where indicated. The error is:
>
> "Column 'TICKETNO' does not belong to table TICKET_DEDUCTIONS."
>
> If I put a breakpoint on that line (so not yet executed) and type
> ?dedrow(c), It says basically the same thing:
>
> Run-time exception thrown : System.ArgumentException - Column 'TICKETNO'
> does not belong to table TICKET_DEDUCTIONS.
>
> But if I type ?dedrow. the intellisense does show that TICKETNO is a
> property.
>
> Does anything jump out at anybody as being blatantly wrong?
>
> Thanks,
> Ron
>
> Here is the code:
>
> For Each dedrow In dsdeductions.TICKET_DEDUCTIONS
> If dedrow(7, DataRowVersion.Original) = drow.cntID Then
> If dedrow.RowState <> DataRowState.Added Then
> ndedrow = DsPurchaseReceiver1.TICKET_DEDUCTIONS.NewRow
> For Each c In DsPurchaseReceiver1.TICKET_DEDUCTIONS.Columns
> If c.ColumnName <> "cntID" Then
> ndedrow(c) = dedrow(c, DataRowVersion.Original) <<<---- ERRORS
> HERE
> End If
> Next
> ndedrow.RecDetailsID = ndrow.cntID
>
> DsPurchaseReceiver1.TICKET_DEDUCTIONS.AddTICKET_DEDUCTIONSRow(ndedrow)
> End If
> End If
> Next
>
>
>
>
>
>
>



 
Reply With Quote
 
=?windows-1253?Q?=C1=ED=F4=FE=ED=E7=F2?=
Guest
Posts: n/a
 
      20th Feb 2007
Have you tried to "Clean Solution" before rebuilding it?
If you are using the Express Edition IDE: delete the "obj" subdirectory
within each project's directory of the solution before rebuilding it.


RobinS wrote:
> First, you need to turn Option Strict On if you don't already have it
> turned on. The reason I think you don't is because of this loop:
>
>> For Each c In DsPurchaseReceiver1.TICKET_DEDUCTIONS.Columns
>> If c.ColumnName <> "cntID" Then
>> ndedrow(c) = dedrow(c, DataRowVersion.Original) <<<---- ERRORS
>> > End If

>> Next

>
> What is "c" ? If it's a column in
> DSPurchaseReceiver1.Ticket_Deductions.Columns, it should be defined as
> such. Is it defined elsewhere in the program?
>
> You can set OptionStrictOn at the top of your routine, but it's recommended
> in VB that you set it in the default project properties and always use it.
> This keeps you from having weird problems where VB is trying to guess what
> type to convert to in order to use a variable that is not defined
> correctly.
>
> Try it and see what problems it reveals.
>
> For example, is dedrow(7) the same data type as drow.cntID?
>
>> If dedrow(7, DataRowVersion.Original) = drow.cntID Then

>
> I can't tell what type some of your variables are, so if you re-post,
> please be more generous in your information, as that might be what's
> causing your problem.
>
> I tried your method using Northwind, and it works fine, as displayed here.
>
> Dim ds As NorthwindDataSet = New NorthwindDataSet()
> Dim custAdapter As CustomersTableAdapter = New CustomersTableAdapter()
> custAdapter.Fill(ds.Customers)
>
> Dim rw As NorthwindDataSet.CustomersRow = _
> DirectCast(ds.Customers.Rows(0), NorthwindDataSet.CustomersRow)
> 'change one value
> rw.PostalCode = "9999"
> 'verify that it's got it
> Console.WriteLine("rw.DataRowVersion.Original = {0}, " & _
> " rw.DataRowVersion.Current = {1}", _
> rw.Item("PostalCode", DataRowVersion.Original), _
> rw.Item("PostalCode", DataRowVersion.Current))
>
> 'move the data from rw to nrw.
> Dim nrw As NorthwindDataSet.CustomersRow = _
> DirectCast(ds.Customers.NewRow(), NorthwindDataSet.CustomersRow)
>
> For Each c As DataColumn In ds.Customers.Columns
> nrw(c) = rw(c, DataRowVersion.Original)
> Next
>
> 'show the new value in the old column
> ' and the proposed value in the nrw row
> For Each c As DataColumn In ds.Customers.Columns
> Console.WriteLine("rw." & c.ColumnName & " = " & _
> rw(c, DataRowVersion.Current).ToString & _
> " nrw = " & nrw.Item(c, DataRowVersion.Proposed).ToString)
> Next
>
>
> Robin S.
> Ts'i mahnu uterna ot twan ot geifur hingts uto.
> -----------------------------------------------
> "Ronald S. Cook" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> In the code below, I get a runtime error where indicated. The error is:
>>
>> "Column 'TICKETNO' does not belong to table TICKET_DEDUCTIONS."
>>
>> If I put a breakpoint on that line (so not yet executed) and type
>> ?dedrow(c), It says basically the same thing:
>>
>> Run-time exception thrown : System.ArgumentException - Column 'TICKETNO'
>> does not belong to table TICKET_DEDUCTIONS.
>>
>> But if I type ?dedrow. the intellisense does show that TICKETNO is a
>> property.
>>
>> Does anything jump out at anybody as being blatantly wrong?
>>
>> Thanks,
>> Ron
>>
>> Here is the code:
>>
>> For Each dedrow In dsdeductions.TICKET_DEDUCTIONS
>> If dedrow(7, DataRowVersion.Original) = drow.cntID Then
>> If dedrow.RowState <> DataRowState.Added Then
>> ndedrow = DsPurchaseReceiver1.TICKET_DEDUCTIONS.NewRow
>> For Each c In DsPurchaseReceiver1.TICKET_DEDUCTIONS.Columns
>> If c.ColumnName <> "cntID" Then
>> ndedrow(c) = dedrow(c, DataRowVersion.Original) <<<---- ERRORS
>> HERE
>> End If
>> Next
>> ndedrow.RecDetailsID = ndrow.cntID
>>
>> DsPurchaseReceiver1.TICKET_DEDUCTIONS.AddTICKET_DEDUCTIONSRow(ndedrow)
>> End If
>> End If
>> Next
>>
>>
>>
>>
>>
>>
>>

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PRB: DataTable.GetErrors.CopyToDataTable() Doesn't Copy the Column Errors Charles Law Microsoft Dot NET 0 6th Sep 2008 06:24 PM
Column does not belong to table error shil Microsoft ASP .NET 0 9th Jan 2007 06:38 PM
Column Does not belong to Table =?Utf-8?B?TWlrZQ==?= Microsoft Dot NET 0 6th Sep 2006 04:04 PM
Re: Column C does not belong to the table T Nicholas Paldino [.NET/C# MVP] Microsoft C# .NET 0 20th Sep 2004 03:10 PM
Column C does not belong to the table T =?Utf-8?B?bWtvbWFzaQ==?= Microsoft C# .NET 0 20th Sep 2004 03:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:56 AM.