Home All Groups Group Topic Archive Search About

How to navigate through dataset

Author
25 Mar 2010 10:49 PM
Jay
I am working with this code for over 2 weeks and I can get this to work with
vb.net. this code works perfectly in vb 6.0. My problem is on how to convert
movefirst and find method from vb6 to vb.net.

Here's the code:

Private Function DeductOnhand(QtyNeeded As Integer, ByVal Order As Integer,
ByVal blnDeduct As Boolean, rs As Recordset) As Boolean
    Dim Onhand As Boolean
    Dim OrderTemp As Integer
    Dim QtyNeededTemp As Double

    Do Until DeductOnhand = True
        OrderTemp = Order
        QtyNeededTemp = QtyNeeded
        rs.Find "Order = " & OrderTemp

        Do Until Onhand = True 'Or OrderTemp = 1
            If rs!Onhand >= QtyNeededTemp Then
                If blnDeduct = False Then
                    DeductOnhand = True
                    Exit Function
                Else
                    Onhand = True
                End If

                If QtyNeededTemp > 0 And QtyNeededTemp < 1 Then
                    QtyNeededTemp = 1
                Else
                    QtyNeededTemp = CInt(QtyNeededTemp)
                End If
            Else
                OrderTemp = OrderTemp - 1
                If OrderTemp < 1 Then Exit Do
                QtyNeededTemp = (QtyNeededTemp - rs!Onhand) / rs!Qty

                rs.MoveFirst

                rs.Find "Order = " & OrderTemp
            End If
        Loop

        If Onhand = True Then
            Do
                rs!Onhand = rs!Onhand - QtyNeededTemp
                OrderTemp = OrderTemp + 1

                rs.MoveFirst
                rs.Find "Order = " & OrderTemp

                rs!Onhand = rs!Onhand + (QtyNeededTemp * rs!Qty)

                rs.Update

                Onhand = False

                If OrderTemp = Order Then
                    DeductOnhand = True
                    Exit Do
                Else
                    DeductOnhand = False
                    Exit Do
                End If
            Loop
        Else
            DeductOnhand = False
        End If
    Loop
End Function

In my vb.net code I tried using the select property of datatable but with no
luck.

Dim dt As DataTable = ds.Tables("ItemsDetails")

dt.Select("OrderNo = " & OrderTemp)

Anyone can please help me what is the equivalent of .movefirst and .find
property of vb6 to vb.net?

Thanks in advance

Author
25 Mar 2010 11:51 PM
Armin Zingler
Am 25.03.2010 23:49, schrieb Jay:
> I am working with this code for over 2 weeks and I can get this to work with
> vb.net. this code works perfectly in vb 6.0. My problem is on how to convert
> movefirst and find method from vb6 to vb.net.
> [...}


As there is no current record in a DataSet or a DataTable, there is nothing to
move. You can access any record in a DataTable by it's index.

  dim row as datarow

  row = dt.rows(17) 'access row with index 17 (= 18th row)


> In my vb.net code I tried using the select property of datatable but with no
> luck.
>
> Dim dt As DataTable = ds.Tables("ItemsDetails")
>
> dt.Select("OrderNo = " & OrderTemp)
>
> Anyone can please help me what is the equivalent of .movefirst and .find
> property of vb6 to vb.net?

The Select method is a function that returns an array of DataRows:

  dim rows as datarow()

  rows = dt.Select("OrderNo = " & OrderTemp)
  if rows.length > 0 then
      msgbox(rows(0)("qty"))
  end if

Or, if OrderNo is the primary key, you can use

   dim row as datarow

   row = dt.rows.find(OrderTemp)


--
Armin
Author
27 Mar 2010 7:39 AM
Cor Ligthert[MVP]
Jay,

You are not the first one trying this, and will be not the last one who sees
that he did things without sense because those methods are often not needed
anymore. This is  because in a dataset everything can direct be selected
while by instance the bindingsource can give the current position (or you
can do it yourself using the currencymanager)

However, if you want to go on in a VB6 way, then Linq to SQL (datacontext)
is probably a better solution for you. That has also like the recordset
possibilities to move to a next row.

Cor

Show quoteHide quote
"Jay" <jpab***@gmail.com> wrote in message
news:uR4s61GzKHA.264@TK2MSFTNGP05.phx.gbl...
> I am working with this code for over 2 weeks and I can get this to work
> with vb.net. this code works perfectly in vb 6.0. My problem is on how to
> convert movefirst and find method from vb6 to vb.net.
>
> Here's the code:
>
> Private Function DeductOnhand(QtyNeeded As Integer, ByVal Order As
> Integer, ByVal blnDeduct As Boolean, rs As Recordset) As Boolean
>    Dim Onhand As Boolean
>    Dim OrderTemp As Integer
>    Dim QtyNeededTemp As Double
>
>    Do Until DeductOnhand = True
>        OrderTemp = Order
>        QtyNeededTemp = QtyNeeded
>        rs.Find "Order = " & OrderTemp
>
>        Do Until Onhand = True 'Or OrderTemp = 1
>            If rs!Onhand >= QtyNeededTemp Then
>                If blnDeduct = False Then
>                    DeductOnhand = True
>                    Exit Function
>                Else
>                    Onhand = True
>                End If
>
>                If QtyNeededTemp > 0 And QtyNeededTemp < 1 Then
>                    QtyNeededTemp = 1
>                Else
>                    QtyNeededTemp = CInt(QtyNeededTemp)
>                End If
>            Else
>                OrderTemp = OrderTemp - 1
>                If OrderTemp < 1 Then Exit Do
>                QtyNeededTemp = (QtyNeededTemp - rs!Onhand) / rs!Qty
>
>                rs.MoveFirst
>
>                rs.Find "Order = " & OrderTemp
>            End If
>        Loop
>
>        If Onhand = True Then
>            Do
>                rs!Onhand = rs!Onhand - QtyNeededTemp
>                OrderTemp = OrderTemp + 1
>
>                rs.MoveFirst
>                rs.Find "Order = " & OrderTemp
>
>                rs!Onhand = rs!Onhand + (QtyNeededTemp * rs!Qty)
>
>                rs.Update
>
>                Onhand = False
>
>                If OrderTemp = Order Then
>                    DeductOnhand = True
>                    Exit Do
>                Else
>                    DeductOnhand = False
>                    Exit Do
>                End If
>            Loop
>        Else
>            DeductOnhand = False
>        End If
>    Loop
> End Function
>
> In my vb.net code I tried using the select property of datatable but with
> no luck.
>
> Dim dt As DataTable = ds.Tables("ItemsDetails")
>
> dt.Select("OrderNo = " & OrderTemp)
>
> Anyone can please help me what is the equivalent of .movefirst and .find
> property of vb6 to vb.net?
>
> Thanks in advance