Re: OleDbDataAdapter created in code behaves differently from one created by wizard.

Tech-Archive recommends: Fix windows errors by optimizing your registry



if you look in the designer, and click on the daA, expand the InsertCommand
property and i'll bet it is empty. you can choose the correct OleDbCommand
object from the menu. then you won't get a NULLreferenceException when you
access daA.InsertCommand.CommandText.

it should be clear from the Exception that the InsertCommand property of the
daA object is set to Null, so when you try and access the CommandText
property of a null object, you get the exception.
a good idea in this case is to debug the code and when the exception
happens, examine the object in question. you'll see in the debugger
<undefined> (i think) next to any null properties.

hope this helps
tim


"tom c" <tomcarr1@xxxxxxxxx> wrote in message
news:1157513300.751253.306230@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I create 2 data OleDbDataAdapters, one with the wizard, and one in
code. I know the adapter created in code is OK because I use it to
fill a data table.

However, when I try to use the same SQL insert statement in the two
adapters, the adapter created with the wizard works fine, but the
adapter created in code gives me an error "Object reference not set to
an instance of an object". The code is below. What am I doing wrong?

'OleDbDataAdapter1 is created by the wizard. daA is created in code.

sqlA = "Select ID1, ID2 from CrossRef"
Dim daA As OleDbDataAdapter = New OleDbDataAdapter(sqlA, ConnA)
OleDbDataAdapter1.InsertCommand.CommandText = SQL 'this works fine
daA.InsertCommand.CommandText = SQL 'this gives an error

What am I missing?



.



Relevant Pages

  • Re: Question on OleDbDataAdapters from a new guy
    ... daA, did a "Quick Watch", and I could see that insertcommand is set to ... I know the adapter created in code is OK because I use it to ... when I try to use the same SQL insert statement in the two ... Dim daA As OleDbDataAdapter = New OleDbDataAdapter ...
    (microsoft.public.dotnet.framework)
  • Re: Question on OleDbDataAdapters from a new guy
    ... daA, did a "Quick Watch", and I could see that insertcommand is set to ... What I still don't understand is how I cerate the insert command. ... I know the adapter created in code is OK because I use it to ... when I try to use the same SQL insert statement in the two ...
    (microsoft.public.dotnet.framework)
  • Re: Question on OleDbDataAdapters from a new guy
    ... daA, did a "Quick Watch", and I could see that insertcommand is set to ... What I still don't understand is how I cerate the insert command. ... I know the adapter created in code is OK because I use it to ... when I try to use the same SQL insert statement in the two ...
    (microsoft.public.dotnet.framework)