473,770 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(OdbcD ataAdapter odbcDataAdapter , string
tableName)
{
DataTable dataTableChange d =

dsTapes.Tables[tableName].GetChanges(Dat aRowState.Added );

if ((dataTableChan ged != null) &&
(dataTableChang ed.Rows.Count 0))
{
// Open the connection if its not already open.
if (odbcConnection .State !=
System.Data.Con nectionState.Op en)
{
odbcConnection. Open();
}

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

try
{
//Submit the changes.
odbcDataAdapter .Update(dsTapes ,
dataTableChange d.TableName.ToS tring());
//Commit the changes and close the connection.
odbcDataAdapter .InsertCommand. Transaction.Com mit();
}
catch (Exception ex)
{

odbcDataAdapter .InsertCommand. Transaction.Rol lback();
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.C ommandText =
"INSERT INTO " + tapeLogODBCName .Trim()
+ " (NBR, Backup_Name, BakDate, ScrDate, Location, "
+ "Tape_No, Tape_Set, Usage, Comment, UseDate) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
tapeLogInsert.P arameters.Add(n ew OdbcParameter(" NBR",
OdbcType.Int));
tapeLogInsert.P arameters["NBR"].SourceColumn = "nbr";
tapeLogInsert.P arameters.Add(" Backup_Name", OdbcType.Char, 17,
"backup_nam e");
tapeLogInsert.P arameters.Add(n ew OdbcParameter(" BakDate",
OdbcType.DateTi me));
tapeLogInsert.P arameters["BakDate"].SourceColumn = "bakdate";
tapeLogInsert.P arameters.Add(n ew OdbcParameter(" ScrDate",
OdbcType.DateTi me));
tapeLogInsert.P arameters["ScrDate"].SourceColumn = "scrdate";
tapeLogInsert.P arameters.Add(" Location", OdbcType.Char, 1,
"location") ;
tapeLogInsert.P arameters.Add(n ew OdbcParameter(" Tape_No",
OdbcType.SmallI nt));
tapeLogInsert.P arameters["Tape_No"].SourceColumn = "tape_no";
tapeLogInsert.P arameters.Add(n ew OdbcParameter(" Tape_Set",
OdbcType.SmallI nt));
tapeLogInsert.P arameters["Tape_Set"].SourceColumn = "tape_set";
tapeLogInsert.P arameters.Add(n ew OdbcParameter(" Usage",
OdbcType.SmallI nt));
tapeLogInsert.P arameters["Usage"].SourceColumn = "usage";
tapeLogInsert.P arameters.Add(" Comment", OdbcType.VarCha r, 50,
"comment");
tapeLogInsert.P arameters.Add(n ew OdbcParameter(" UseDate",
OdbcType.DateTi me));
tapeLogInsert.P arameters["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!

Jul 10 '06 #1
0 2115

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
24723
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream s); public void Deserialize(Stream s); Within the MyUserControl class, there is a field of type MyInnerClass
6
2503
by: Babu Mannaravalappil | last post by:
Can somebody please help me figure out why the following method exceptions out? Execution at the line marked with ********** hangs for about 15 seconds and then I get an error that says an Unhandled StackOverFlowException occurred. The execution does not even get passed to the catch block. At the time of my test, only one of 12 tables in the dataset (catalogsDS) really has changes. The dataset is not a huge one. Most tables have less...
5
2384
by: Steve B. | last post by:
A particular column in my Access DB table, and the associated datagrid, cannot have duplicate string entries. I've selected "Yes (no duplicates)" for the Indexed Field Property of this column in the Access table. When I call update(), the DB gets updated but throws an exception saying, in affect, that I'm trying to change the key. This column is not the key. How do I handle this? How do I stop the ex.message being thrown? I guess I...
2
6085
by: Stanav | last post by:
Hello all, I'm developing a web application using VB.Net 2003 and Framework 1.1. This application queries an AS/400 database. I'm using the IBM OleDb provider that came with IBM Client Access for Windows (V5R3). Everything works fine on my development PC, but when I move the application to a Windows Server 2003, it crashes when trying to fill a dataset. I've double-checked that the Win 2k3 server does have Client Access installed, that it...
3
3274
by: Chris Thunell | last post by:
I am trying to delete all the records in a table, but I keep getting a system.data.dbconcurrency exception. Is there an easy was to delete all the records in a sql table? Here is my code... i get the error on the dataadapter.update: MessageBox.Show(Me.DataSet11.tblPreReqWorking.Rows.Count) 'get rid of any records in memory Me.DataSet11.tblPreReqWorking.Clear() Me.daPreReqWorking.SelectCommand.CommandText = "Select JobNo, ReqNo, SeqNo
0
1087
by: Lucas Tam | last post by:
Is there a way to call DataAdapter.Update from a Dataview when I have no reference to the DataAdapter? i.e. The DataView is a class variable however the dataadapter is a local variable in a sub procedure. From another sub procedure is it possible to call a dataadapter.update or similar? Psuedo code is as follows: Dim _dv as dataview
12
16768
by: Joe | last post by:
I might be overworked so please excuse this stupid question... Say I do the following: DataTable table = new DataTable(); myDataAdaptor.Fill(table); dataGrid1.DataSource = table;
11
3266
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When my object is destroyed, I want my object to un-register this event. If I don't then the object would never be destroyed until the object I passed in the constructor is destroyed. I have implemented a Dispose(), Dispose(bool), and ~Finalize...
2
3881
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously stated. Also please note that this is unrelated to another of my previous threads, “dataAdapter.Update problem”, which incidentally has been resolved. I’m learning SQL. I’m accessing database SQL2008 AdventureWorks, table Person.Contact, which has a...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.