Solved

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

Posted on 2007-04-10
2
206 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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

18 Experts available now in Live!

Get 1:1 Help Now