[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

First person to solve this wins 500 points

Posted on 2006-07-14
11
Medium Priority
?
391 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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