Solved

Problen converting data in a Datarow

Posted on 2007-03-29
2
280 Views
Last Modified: 2010-04-23
Hi,
I need help converting VB6 DAO code to VB.NET 2003 code with ADO.NET. Here is my old code:

For i% = 0 To RS.Fields.count - 2
           Select Case i%
            Case 0, 1, 2
                RS2.Fields(i%).value = RS.Fields(i%).value
            Case 3
                RS2.Fields(i%).value = PhysUnit$(AinPhysTyp%(AinIDcol(RS.Fields(0).value)), UnitsISO%)
            Case Is > 4
                RS2.Fields(i%).value = ConvertEMUtoISO!(AinPhysTyp%(AinIDcol(RS.Fields(0).value)), RS.Fields(i%).value)
         End Select
      Next
This code moves some records from 1 table and adds them to another. Basically what happens here is that if the Case is 3 then the column in the old table contains English Measurement Units (such as F, feet, lbs, etc) The RS2 field then gets assigned the corresponding Metric Unit (C, Meters, Kg, etc)
If the case is > 4 then the old table contains an English Measurement Value (for example 32 or 212) Assuming this is a Temperature then the RS2 field would get set to 0 (for 32F) or 100 (for 212F)

My new code in VB.NET is below:
For Each dr As DataRow In dt101.Rows
            Dim drn As DataRow = dt404.NewRow
            For i As Integer = 0 To 4
                Select Case i
                    Case 0, 1
                        drn.Item(i) = dr.Item(i)
                    Case 2
                        drn.Item(i) = PhysUnit$(AinPhysTyp%((dr.Item(i).tostring())), UnitsISO%)
                    Case 3, 4
                        drn.Item(i) = ConvertEMUtoISO!(AinPhysTyp%(AinIDcol(dr.Item(i))), dr.Item(i).value)
                End Select
            Next
            dt404.Rows.Add(drn)
        Next

In this case dr is the datarow in the old table and drn is the new datarow in the new table. and Case 2 is the Unit column and Case 3 and 4 are LowLimit and HighLimit respectively (Case 3 and 4 are numeric)

The new code as shown above does not work for Case 2, 3 or 4 and I think I am doing something wrong in identifying the row information. In case 2 I tried using toString as shown above and for case 3 and 4 I attempted to use VALUE which also does not work.

Can anyone offer any help with this one?

Thanks,
Charlie
0
Comment
Question by:charlieb01
  • 2
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 18815356
DataRow.Item already returns the value in the relevant cell but As Object.  It looks like your functions might be requiring specific datatypes.  So try express conversions: CStr(dr.Item(i)) where you execting a String and CInt(dr.Item(i)) where you are expecting an Integer, etc.

Roger
0
 
LVL 34

Expert Comment

by:Sancler
ID: 18815383
For a more detailed run over the relevant stuff, look for "Implicit and Explicit Conversions" in the help files, or see this

   http://msdn2.microsoft.com/en-us/library/kca3w8x6(VS.80).aspx

Roger
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

Suggested Solutions

Title # Comments Views Activity
VB 2005 Tooltips on Form Load Event 15 34
VB.NET 2008 - SQL Timeout 9 34
Optimize the query 5 42
Import MySQL data into MS Access using VB.Net interface 5 24
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

765 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