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
tableName)
{
DataTable dataTableChanged =

dsTapes.Tables[tableName].GetChanges(DataRowState.Added);

if ((dataTableChanged != null) &&
(dataTableChanged.Rows.Count > 0))
{
// Open the connection if its not already open.
if (odbcConnection.State !=
System.Data.ConnectionState.Open)
{
odbcConnection.Open();
}

//Create a new transaction.
odbcDataAdapter.InsertCommand.Transaction =
odbcConnection.BeginTransaction();

try
{
//Submit the changes.
odbcDataAdapter.Update(dsTapes,
dataTableChanged.TableName.ToString());
//Commit the changes and close the connection.
odbcDataAdapter.InsertCommand.Transaction.Commit();
}
catch (Exception ex)
{

odbcDataAdapter.InsertCommand.Transaction.Rollback();
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",
OdbcType.Int));
tapeLogInsert.Parameters["NBR"].SourceColumn = "nbr";
tapeLogInsert.Parameters.Add("Backup_Name", OdbcType.Char, 17,
"backup_name");
tapeLogInsert.Parameters.Add(new OdbcParameter("BakDate",
OdbcType.DateTime));
tapeLogInsert.Parameters["BakDate"].SourceColumn = "bakdate";
tapeLogInsert.Parameters.Add(new OdbcParameter("ScrDate",
OdbcType.DateTime));
tapeLogInsert.Parameters["ScrDate"].SourceColumn = "scrdate";
tapeLogInsert.Parameters.Add("Location", OdbcType.Char, 1,
"location");
tapeLogInsert.Parameters.Add(new OdbcParameter("Tape_No",
OdbcType.SmallInt));
tapeLogInsert.Parameters["Tape_No"].SourceColumn = "tape_no";
tapeLogInsert.Parameters.Add(new OdbcParameter("Tape_Set",
OdbcType.SmallInt));
tapeLogInsert.Parameters["Tape_Set"].SourceColumn = "tape_set";
tapeLogInsert.Parameters.Add(new OdbcParameter("Usage",
OdbcType.SmallInt));
tapeLogInsert.Parameters["Usage"].SourceColumn = "usage";
tapeLogInsert.Parameters.Add("Comment", OdbcType.VarChar, 50,
"comment");
tapeLogInsert.Parameters.Add(new OdbcParameter("UseDate",
OdbcType.DateTime));
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!

.



Relevant Pages

  • Re: Dataset retunring Null ..a gurus opinion required!
    ... How is estateOleAdapter initialized? ... toolbox to the design area to establish the connection. ... application this exception comes up): ... When adding a reference, I tried "Add Service Reference" and I also ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: "invalid handle", sockets, threads and garbage collector
    ... your IntPtr value happens to coincide with a reference. ... The exception contains "invalid handle" message. ... Socket constructor problem ... finalization means closing the handle to resource. ...
    (microsoft.public.dotnet.framework.clr)
  • Global Assembly Cache Issue
    ... I have a dll that I use in several projects, that I placed in the Global ... you can see in the Exception below). ... If I change the Copy Local property of the reference to True, ... Attempting download of new URL ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: newbie: deactivate query before freeing?
    ... but the exception will still be thrown. ... There is exactly one invalid reference, the null pointer, nil. ... abort the normal flow of execution and start handling the exception ...
    (comp.lang.pascal.delphi.misc)
  • Re: PowerPoint shapeId/ShapeName property changes/Increments autom
    ... I agree with what u r saying, reference is stored in a shape type variable ... which result in a com exception in my code. ... >> I am posting a small sample code to better explain my problem ... >> Sub Testing() ...
    (microsoft.public.office.developer.vba)