?
Solved

First person to solve this wins 500 points

Posted on 2006-07-14
11
Medium Priority
?
385 Views
Last Modified: 2008-01-09
For i = 0 To NewProgram.ItemArray.Length - 1
         If Not IsDBNull(CurrentProgram.ItemArray(i)) Then NewProgram.ItemArray.SetValue(CurrentProgram.ItemArray(i), i)
Next
         
Why does this NOT update the newprogram.ItemArray values?

The newprogram and current program are both strong typed datarows.  They have over 75 Fields, and it would be soooooo much nicer to copy using the correct method.  Cheers.

PS I have stepped in the debugger and I have definately confirmed that when the value is not null, it does not copy (ie executes the line after the then) and each item in teh newprogram.itemarray is null.

GRRRR
0
Comment
Question by:spinalogic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 

Author Comment

by:spinalogic
ID: 17106427
let me clarify the debugging part

The line after the then DOES execute.

However the newprogram.itemarray(i) value remains as null.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 17106464
Hi spinalogic,
----------

looking at your code this is VB instead of C#
but for the problem, i've no idea because its a bit difficult to debug but you can try to clone the object into the new array like

For i = 0 To NewProgram.ItemArray.Length - 1
  If Not IsDBNull(CurrentProgram.ItemArray(i)) Then NewProgram.ItemArray.SetValue(CurrentProgram.ItemArray(i).Clone(), i)
Next

and be sure the newprogram array is initialized but i don't think that is the problem becuase you get no warning or other message in the error window ...

----------
bruintje
0
 

Author Comment

by:spinalogic
ID: 17106475
The object is created using the newstrongtypedrow function (newPatientsCareProgramrow) function

I'll try clone
Egad, I don't know how VB objects work, I'm a java programmer by trade. I'd be happy with C# but I work for money and I do what I'm told.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:spinalogic
ID: 17106486
Clone isn't a public member of most of the types out of the datagrid (Guid in particular)

So what else can we try.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 17106503
are you trying to copy data grid values from one datagrid to another?
0
 

Author Comment

by:spinalogic
ID: 17106515
no.

I have a strong typed data row that I wish to copy to a NEW datarow, and then modify some value on the NEW one.
IE Find a row
Copy row
Change its PK and relevant fields
Update DB

I was using that iterator to copy each column. But that doesn't update a single field on the newprogram row.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 17106645
if i understand the benefit of the strongly typed datarow you can alos try to copy the values directly from the one to the other like

If Not IsDBNull(CurrentProgram.ItemArray(i)) Then
    with NewProgram.ItemArray(i)
        .PK = CurrentProgram.ItemArray(i).PK
        .relevantfields = CurrentProgram.ItemArray(i).relevantfields
    end with
end if
0
 
LVL 5

Accepted Solution

by:
pgloor earned 2000 total points
ID: 17106833
Try to assign the data to DataRow.Item( index ) instead of using DataRow.ItemArray.SetValue

For i = 0 To NewProgram.ItemArray.Length - 1
         If Not IsDBNull(CurrentProgram.ItemArray(i)) Then NewProgram.Item(i) = CurrentProgram.Item(i)
Next

Not sure this is the correct way to do but it might work.

If you are just looking for a way to copy (clone) datarows from one table to another you might also read this article in the knowledge base (C#):

http://support.microsoft.com/default.aspx?scid=kb;en-us;q308909
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17108223
There is a distinction between null and DBNull, so you have to be clear about that.  Which is it?  What type is stored in CurrentProgram?

Bob
0
 

Author Comment

by:spinalogic
ID: 17112433
The values on the new Row start as DBNull.value and remain DBNull.Value after the .setvalue command.

Bruintje is very correct. HOWEVER there are over 75 columns on this datarow, and each has to be checked for nulls, and very tedious set of typing for every single name.  So although what you said is valid, its not quite what I'm after. And that c# "with" operator looks v cool :D. Never seen it before.

I couldn't obtain the count of the item collection, and I don't know whether its 75 or what else was in it.  I'll give your suggestion a go pgloor and then I'll go from there.
0
 

Author Comment

by:spinalogic
ID: 17116114
Worked first time.

Thats very weird that the itemarray doesn't work though?  Perhaps I have misunderstood their object model, but there was no count variable on the row object, so it was impossible to directly derive how many columns there were without using it.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question