# VB.net 2008 | ODBC | Move Backwards



## RBX (Sep 1, 2011)

We have been told to work on Video Library in DBMS lab using VB and MS Access, however no lessons on how to do it were given. No one knows how to work in VB.

The Database connectivity is quite easy using ADO is VB6 which sadly doesn't work very well in Windows 7 so I'm using VB.net 2008 with ODBC.

Here's the code -


```
Imports System.Data.Odbc
Public Class CreateConnection
    Dim con As New OdbcConnection("DSN=VideoLib;")
    Dim cmd As New OdbcCommand
    Public ID As Integer
    Public VidName As String
    Public Price As Integer
    Public odbcReader As OdbcDataReader

    Public Sub New()
        con.Open()
        cmd.Connection = con
        cmd.CommandText = "SELECT * FROM Video"
        odbcReader = cmd.ExecuteReader()
    End Sub

    Public Sub MoveNext()
        If (odbcReader.Read() = True) Then
            ID = odbcReader.GetInt32(0)
            VidName = odbcReader.GetString(1)
            Price = odbcReader.GetInt32(2)
        End If
    End Sub

    Public Sub Creates()
        cmd.CommandText = "INSERT INTO Video(ID,Video_Name,Price) VALUES(" + CType(ID, String) + ",'" + VidName + "'," + CType(Price, String) + ")"
        cmd.ExecuteNonQuery()
    End Sub
End Class
```

The MoveNext() function works as intended but OdbcDataReader's Read() method moves only forward and I'm unable to move backwards. 
Please provide some assistance on this


----------



## asingh (Sep 1, 2011)

Why would you want to move back in the recordset.


----------



## RBX (Sep 1, 2011)

That's what my Teacher wants. Textboxes display current record's data and like in ADO, I have to move - Forward, Backward, First, Last.
I could store each record in Arrays and use them for MovePrevious, First, Last etc but that doesn't seem very practical approach considering the space complexity.


----------

