Re: OleDbDataAdapter created in code behaves differently from one created by wizard.
- From: "Tim_Mac" <tim.mackey@xxxxxxxxxxxxxxxx>
- Date: Wed, 6 Sep 2006 09:05:22 +0100
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?
.
- References:
- Prev by Date: Re: Populating Controls - Form Load Dynamically
- Next by Date: Re: Error BC30451
- Previous by thread: OleDbDataAdapter created in code behaves differently from one created by wizard.
- Next by thread: Re: OleDbDataAdapter created in code behaves differently from one created by wizard.
- Index(es):
Relevant Pages
|