Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

830 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