Tip Translation to ADO.NET

therealzeta

Member
Joined
Aug 9, 2008
Messages
19
Programming Experience
5-10
Hello, I have this code in vb6 to manipulate recordsets. The problem is that i need to migrate urgently to .net and i would to traslate it to .net. As u can see, there is a function (getMeRecordsNormal) that connect to the database.
Does anybody has the proper code in .net??? I would apreciate ur help.

VB.NET:
Public Sub RecordSetTemplate()
'Dim ssql As String
'Dim rs As New ADODB.Recordset
'
'
'    On Error GoTo errHnadler
'    Screen.MousePointer = vbHourglass
'
'    ssql = " SSQL SSQL SSQL SSQL SSQL SSQL SSQL "
'    Set rs = getMeRecordsNormal(ssql)
'
'    If Not rs Is Nothing Then
'        If rs.State Then
'            If Not rs.EOF Then
'                rs.MoveFirst
'
'
'            End If
'            Call rs.Close
'        End If
'        Set rs = Nothing
'    End If
'
'
'    Screen.MousePointer = vbDefault
'    Exit Sub
'errHnadler:
'    Screen.MousePointer = vbDefault
'    If Not rs Is Nothing Then
'        If rs.State Then
'            Call rs.Close
'        End If
'        Set rs = Nothing
'    End If

    MsgBox Err.Description, vbCritical, msgTitulo
End Sub
 
This should get you close enough to make any changes and do what you want to do:

VB.NET:
Public Sub RecordSetTemplate()
        Me.Cursor = Cursors.WaitCursor

        Try
            Using conn As New SqlConnection("connection string here")
                conn.Open()

                Using cmd As New SqlCommand("sql query here")
                    cmd.Connection = conn

                    Using dr = cmd.ExecuteReader
                        While dr.Read()
                            ' Process records here
                            dr("column name here").ToString()
                        End While
                    End Using
                End Using
            End Using

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            ' Log error or do other processing
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub

CT
 
Back
Top