Solved

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

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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