DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Null reference exception when trying to use DataAdapter Update

  1. #1
    Join Date
    Jul 2006

    Null reference exception when trying to use DataAdapter Update

    I keep getting an exception when I call the DataAdapter Update method.
    I have been trying to figure out what is causing the null reference
    exception for this code for what seems like forever:

    private void DoInserts(OdbcDataAdapter odbcDataAdapter, string
    DataTable dataTableChanged =


    if ((dataTableChanged != null) &&
    (dataTableChanged.Rows.Count > 0))
    // Open the connection if its not already open.
    if (odbcConnection.State !=

    //Create a new transaction.
    odbcDataAdapter.InsertCommand.Transaction =

    //Submit the changes.
    //Commit the changes and close the connection.
    catch (Exception ex)

    throw (ex);

    The exception information has not been helpful. All it says is: "Object
    reference not set to an instance of an object."

    I don't know if this will help, but the Insert command looks like this:

    tapeLogInsert = odbcConnection.CreateCommand();
    tapeLogInsert.CommandText =
    "INSERT INTO " + tapeLogODBCName.Trim()
    + " (NBR, Backup_Name, BakDate, ScrDate, Location, "
    + "Tape_No, Tape_Set, Usage, Comment, UseDate) "
    + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    tapeLogInsert.Parameters.Add(new OdbcParameter("NBR",
    tapeLogInsert.Parameters["NBR"].SourceColumn = "nbr";
    tapeLogInsert.Parameters.Add("Backup_Name", OdbcType.Char, 17,
    tapeLogInsert.Parameters.Add(new OdbcParameter("BakDate",
    tapeLogInsert.Parameters["BakDate"].SourceColumn = "bakdate";
    tapeLogInsert.Parameters.Add(new OdbcParameter("ScrDate",
    tapeLogInsert.Parameters["ScrDate"].SourceColumn = "scrdate";
    tapeLogInsert.Parameters.Add("Location", OdbcType.Char, 1,
    tapeLogInsert.Parameters.Add(new OdbcParameter("Tape_No",
    tapeLogInsert.Parameters["Tape_No"].SourceColumn = "tape_no";
    tapeLogInsert.Parameters.Add(new OdbcParameter("Tape_Set",
    tapeLogInsert.Parameters["Tape_Set"].SourceColumn = "tape_set";
    tapeLogInsert.Parameters.Add(new OdbcParameter("Usage",
    tapeLogInsert.Parameters["Usage"].SourceColumn = "usage";
    tapeLogInsert.Parameters.Add("Comment", OdbcType.VarChar, 50,
    tapeLogInsert.Parameters.Add(new OdbcParameter("UseDate",
    tapeLogInsert.Parameters["UseDate"].SourceColumn = "usedate";
    tapeLogAdapter.InsertCommand = tapeLogInsert;

    Does any one have any idea what is going on here or how to go about
    finding out? Any suggestions would be appreciated: I don't even know
    how to figure out which reference is null!

  2. #2
    Join Date
    Dec 2004
    AFAIK, This error "Object reference not set to an instance of an object." is used to raise when the variable is null..
    You write like that.

    DataAdapter da = DataAdapter(); 
    da.DoSomething(); // << Here you will get this error..
    So, You have to initialize one instance of the object.

    DataAdapter da = new DataAdapter(); 
    da.DoSomething(); // << It's working...
    Here is what ms says.
    FIX: You may receive the "Object reference not set to an instance of an object" error message in the .NET Framework 1.1 Service Pack 1
    When you create a program by using Microsoft Visual Studio .NET 2003 and the Microsoft .NET Framework 1.1 Service Pack 1, your program may exhibit unexpected behavior. When you modify a value in a row in a child table of the DataGrid control, you may receive the following error message:An unhandled exception of type 'System.NullReferenceException' occurred in
    Additional information: Object reference not set to an instance of an object
    You receive the previous error message when you press BACKSPACE.
    Back to the top

    A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that this article describes. Apply it only to systems that are experiencing this specific problem.

    To resolve this problem, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services phone numbers and information about support costs, visit the following Microsoft Web site:;[LN];CNTACTMS
    Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

    The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel. Date Time Version Size File name
    12-Nov-2004 15:53 1.1.4322.2047 2,052,096
    What I like to suggest is that you should check whether odbcDataAdapter is NULL or not in debugging mode.
    Best Regards,
    Michael Sync

    The more you share,The more you get

Similar Threads

  1. Getting a GUI to run
    By Eric in forum Java
    Replies: 4
    Last Post: 04-14-2006, 09:09 AM
  2. Delete all records
    By vanaxel in forum Java
    Replies: 15
    Last Post: 04-10-2006, 05:20 AM
  3. Table not updating on NULL
    By Billkamm in forum Database
    Replies: 0
    Last Post: 01-30-2006, 03:54 PM
  4. Getting a large number of identities
    By Colin McGuigan in forum Database
    Replies: 12
    Last Post: 04-15-2002, 07:43 AM
  5. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 07:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center