Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with dataset, db2 connection, data adapter   when not pulled from tool box

Posted on 2007-04-10
2
Medium Priority
?
210 Views
Last Modified: 2013-11-26
I am trying to verify an insert before executing an Insert to a DB2 table thru a vb.net program.  The code looks like this:
  Private Sub Test_the_insert()
        Dim strSQL2 As String = "Select TC_EMRG_DIAG_CD FROM " & _
            "TCDVLP.TC-EMRG_DIAG_CD WHERE TC_EMRG_DIAG_CD = " & _
            "'" & txtDiagCD.Text & "'"
        Dim cnTestIns As New OleDb.OleDbConnection("Provider=IBMDADB2.1;" & _
        "Mode=ReadWrite;User ID=xxxxxxxx;Data Source=xxxx;Extended Prop" & _
          "erties=;Password=yyyyy")
        Dim daTestIns As New OleDb.OleDbDataAdapter(strSQL2, cnTestIns)

        Dim ds3 As DataSet
        Try
            cnTestIns.Open()
        Catch ex As Exception
            MessageBox.Show("0 " & Convert.ToString(ex.Message))
        End Try

        Try
            daTestIns.Fill(ds3, "Table1")
            cnTestIns.Close()
            cnTestIns.Dispose()
            MessageBox.Show("Insert has data Tested not ok!")
            boolGoodIns = False
        Catch ex As Exception
            MessageBox.Show("1 " & Convert.ToString(ex.Message))
            MessageBox.Show("An error has occurred!")
        End Try
    End Sub

The program takes the catch path (immediately above)  even when I use a record that has a record already on the table,  So the dataset should not be null.  The funny thing is that when I pull the control from the toolbox, and generate the dataset it seems to work.  When I define it in the program, it doesn't.  I have done mostly the same thing with sql server and oracle.  I just can't see the problem the specific error:

Value cannot be null, parameter name dataset.

When I get past this problem, I plan to test the dataset to see if I returned data, if I did the insert is not allowed, no data means clear to insert.
 
0
Comment
Question by:garyinmiami2003
[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
2 Comments
 
LVL 18

Accepted Solution

by:
Ajay Sharma earned 2000 total points
ID: 18882266
u have to initilize the dataset object.

Dim strSQL2 As String = "Select.........."
        Dim cnTestIns As New OleDb.OleDbConnection(".......")
        Dim daTestIns As New OleDb.OleDbDataAdapter(strSQL2, cnTestIns)

        Dim ds3 As new DataSet
        Try
            cnTestIns.Open()
        Catch ex As Exception
            MessageBox.Show("0 " & Convert.ToString(ex.Message))
        End Try

        Try
            daTestIns.Fill(ds3, "Table1")
            cnTestIns.Close()
            cnTestIns.Dispose()
            MessageBox.Show("Insert has data Tested not ok!")
            boolGoodIns = False
        Catch ex As Exception
            MessageBox.Show("An error has occurred!")
        End Try
    End Sub



http://www-128.ibm.com/developerworks/db2/library/techarticle/0307swart/0307swart.html

http://www-128.ibm.com/developerworks/db2/library/techarticle/0307swart/0307swart.html

0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 18882281
can you post the output of the program ?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

730 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