How to execute Store Procudure on IBM AS400-iSeries-System database ?


Hi

Recently i got the chance to work with IBM AS400-iSeries-System database i.e mainframe database. Process is very much similar to ado.net approach.

Firstly you have to install drive i.e IBM i Access for Windows

Then add the IBM.Data.DB2.iSeries dll in your application.

Now you can write the code like this.

Imports IBM.Data.DB2.iSeries

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

 Dim con As New iDB2Connection("Data source=000.100.00.11;User Id=Test;Password=Test")
        con.Open()
        Dim cmd As New iDB2Command()
        cmd = con.CreateCommand()
        cmd.CommandText = "trs.Test"
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@lib1", "TEL")
        cmd.Parameters.AddWithValue("@sUser", "admin")
        cmd.Parameters.AddWithValue("@ErrorMsgId", "")
        cmd.Parameters.AddWithValue("@ErrorMsg", "")
        cmd.Parameters("@ErrorMsgId").Direction = ParameterDirection.Output
        cmd.Parameters("@ErrorMsg").Direction = ParameterDirection.Output
        Dim da As New iDB2DataAdapter(cmd)
        Dim dt As New DataTable()
        da.Fill(dt)
        Dim msg As String = cmd.Parameters("@ErrorMsgId").Value
        Dim msg1 As String = cmd.Parameters("@ErrorMsg").Value


    End Sub


End Class

It will fetch the data from database.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: