Solved

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

Posted on 2007-04-10
2
204 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
2 Comments
 
LVL 18

Accepted Solution

by:
Ajay Sharma earned 500 total points
Comment Utility
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
Comment Utility
can you post the output of the program ?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now