INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How-to

Create a connection to an AS400 by Bruce1965
Posted: 28 Feb 06

Create a connection to an AS400 and fill a list view with results

Copy all the steps into an event and try it ....

Step 1

CODE

'Define the ODBC Connection string
 Dim MyODBCConnection As New OdbcConnection("Driver={Client Access ODBC Driver (32-bit)};" & _
        "System=AS400Name;" & _
        "TRANSLATE=1;" & _
        "Uid=UserID;" & _
        "Pwd=User Password")
'Open the connection
        MyODBCConnection.Open()


Step 2

CODE

'Define the SQL statement to extract the data from the AS400
Dim selectCMD As OdbcCommand = New OdbcCommand("SELECT * FROM LIBRARY.FILE WHERE FILEFIELD='YourChoice' order by FILEFIELD", MyODBCConnection)


Step 3

CODE

'Initialize the reader
Dim dr As OdbcDataReader = selectCMD.ExecuteReader


Step 4

CODE

Try
'Set the mouse to show a Wait cursor
            Me.Cursor = Cursors.WaitCursor
'start the Read loop
            While dr.Read
'Note: the numbers in double quotes represent the column number from the AS400 database
'Add the data to the list view
                Dim listItem As New ListViewItem(dr.GetString("2"))
                listItem.SubItems.Add(dr.GetString("3"))
                ListView1.Items.Add(listItem)
'End the loop
            End While
'Reset the cursor
            Me.Cursor = Cursors.Default

        Catch ex As Exception
        End Try


Step 5

CODE

'Close the connection
 MyODBCConnection.Close()
 MyODBCConnection.Dispose()



And that's all there is to it. Of course, this is probably the simplest scenario, but you get the idea - you can build on this!

2thumbsup

Back to Visual Basic (Microsoft) VB.NET FAQ Index
Back to Visual Basic (Microsoft) VB.NET Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close