Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.NET and AS/400 connection and bind to datagrid?

Posted on 2006-06-12
3
Medium Priority
?
542 Views
Last Modified: 2008-02-01
How do I set up ODBC for the AS400 (DB2) and bind to a datagrid?
0
Comment
Question by:bfth1505
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Expert Comment

by:vadim63
ID: 16888531
0
 
LVL 1

Accepted Solution

by:
donhenderson1961 earned 2000 total points
ID: 16894389
Alter this to suit your needs:

Private Sub btnRetrieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetrieve.Click
        Dim strConnection As String
        Dim strSQL As String
        btnReport.Enabled = False
        'Replace the connection string
        strConnection = "Driver={Client Access ODBC Driver (32-bit)};System=<ip address>;UID=ODBCUSER;PWD=<pwd>;"
        'strConnection = "Driver={Client Access ODBC Driver (32-bit)};System=<ip address>;UID=ODBCUSER;PWD=<pwd>;"
        Dim objConnection As New Odbc.OdbcConnection(strConnection)
        Dim objCommand As Odbc.OdbcCommand
        Me.Cursor = Cursors.WaitCursor
        Try
            If ValidateWindow() Then
                Dim strFromDate As String = Mid(dtpFromDate.Text, 7, 2) & Mid(dtpFromDate.Text, 9, 2) & Mid(dtpFromDate.Text, 1, 2) & Mid(dtpFromDate.Text, 4, 2)
                Dim strToDate As String = Mid(dtpToDate.Text, 7, 2) & Mid(dtpToDate.Text, 9, 2) & Mid(dtpToDate.Text, 1, 2) & Mid(dtpToDate.Text, 4, 2)
                Dim intFromDate As Integer
                Dim intToDate As Integer
                intFromDate = strFromDate
                intToDate = strToDate


                If txtFromClient.Text <> "" Then
                    strSQL = "Select pcomp, cltgrp, pclnt#, glast, gfirst, pdate, ptype, payamt, pbalaf, gdebt#, pcomm, pguar#, cltgrp, gcomp, ccomp, cclnt" & _
                             " from data.scpaymi, data.scacct, data.scclnt" & _
                                 " Where pcomp = gcomp and pguar# = gdebt# and pcomp = ccomp and pclnt# = cclnt" & _
                                        " And pcomp = " & txtDivision.Text & _
                                        " And cclnt >= " & txtFromClient.Text & " and cclnt <= " & txtToClient.Text & _
                                        " And pdate >= " & intFromDate & " And pdate <= " & intToDate & _
                                        " order by pcomp, pclnt#, glast, gfirst"
                Else
                    strSQL = "Select pcomp, cltgrp, pclnt#, glast, gfirst, pdate, ptype, payamt, pbalaf, gdebt#, pcomm, pguar#, cltgrp, gcomp, ccomp, cclnt" & _
                                    " from cdata.scpaymi, data.scacct, data.scclnt" & _
                                    " Where pcomp = gcomp and pguar# = gdebt# and pcomp = ccomp and pclnt# = cclnt and " & _
                                    "pcomp = " & txtDivision.Text & _
                                    " and cltgrp = " & txtClientGroup.Text & _
                                    " And pdate >= " & intFromDate & _
                                    " and pdate <= " & intToDate & _
                                    " order by pcomp, cltgrp, pclnt#, glast, gfirst"
                End If

                lblError.Text = "Attempting connection"

                objCommand = New Odbc.OdbcCommand(strSQL)
                objCommand.Connection = objConnection

                Dim dareport As New Odbc.OdbcDataAdapter(objCommand)
                Dim dsReport As New DataSet
                dareport.Fill(dsReport)

                Dim dvLocalReport As DataView = dsReport.Tables(0).DefaultView
                dvLocalReport = dsReport.Tables(0).DefaultView
                dgPaymentRpt.DataSource = dvLocalReport
                dgPaymentRpt.SetDataBinding(dvLocalReport, "")

                Me.ReportDataView = dvLocalReport

                lblError.Text = lblError.Text & vbCrLf & "Retrieve complete, no error."
            End If
            If Me.ReportDataView.Count = 0 Then
                lblNoRecords.Visible = True
                btnReport.Enabled = False
            Else
                btnReport.Enabled = True
                lblNoRecords.Visible = False
            End If

        Catch ex As Odbc.OdbcException
            btnReport.Enabled = False
            lblValidationError.Text = "Is the VPN connected?" & vbCrLf & "Is the ISeries setup?"
            lblError.Text = "btnRetrieve_Click: ODBC ERROR" & vbCrLf & "ex.Source: " & ex.Source & vbCrLf & "ex.Message: " & ex.Message & vbCrLf & " Stack Trace: " & ex.StackTrace
        Catch ex As Exception
            btnReport.Enabled = False
            lblValidationError.Text = "Is the VPN connected?" & vbCrLf & "Is the ISeries setup?"
            lblError.Text = "btnRetrieve_Click: Exception ERROR" & vbCrLf & "ex.Source: " & ex.Source & vbCrLf & "ex.Message: " & ex.Message & vbCrLf & " Stack Trace: " & ex.StackTrace
        Finally
            Me.Cursor = Cursors.Arrow
            objCommand = Nothing
            If objConnection.State = ConnectionState.Open Then
                objConnection.Close()
            End If
            objConnection = Nothing
        End Try
    End Sub
0
 

Author Comment

by:bfth1505
ID: 16894414
Wow, what a great answer.  I put it into my application and altered a few lines and it worked perfectly.  Thanks Don, that is a very professional answer!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question