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
>
>
>
>
>
>
>
|