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



hi tom,
no problem. debugging is a truly essential skill for a developer, i'm glad
you got it going. whenever anything goes wrong in your code now, you can
jump right in with the debugger and identify the problem point quickly.

usually what happens with the dataAdapters is you configure them in the VS
designer. if you choose the SQL statement option, then it will
automatically generate OleDbCommand objects for Update,Delete,Insert and
Select, and attach them correctly to the DataAdapter.
if you choose Stored Procedures then you have to instruct VS which sproc
should be used for each of the 4 commands. if you leave out any of the 4
command types, then there will be no OleDbCommand object for that function
type (Insert/Update etc).

if you then look in the code behind, you will see 4 OleDbCommand objects
called OleDbSelectCommand1, OleDbInsertCommand1 etc.

you can re-configure the dataadapter by right-clicking it in the VS
designer.
alternatively you can expand the InsertCommand property of the dataAdapter
in the VS designer and choose 'new' from the menu. then you can set up the
command as you like, setting the connection, commandText properties etc.

does that make sense?
tim




"tom c" <tomcarr1@xxxxxxxxx> wrote in message
news:1157552634.605426.76570@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks so much Tim.

You are correct. I used the debugger, set a break point, right clicked
daA, did a "Quick Watch", and I could see that insertcommand is set to
nothing.
I didn't know you could do that.

What I still don't understand is how I cerate the insert command.

How do I do that? What was left out of my original code that is needed
to create the insert, update and delete commands?

Tom


Tim_Mac wrote:
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

  • Debugging
    ... On my WinXP Professional box at home, I can't get the debugger to start from ... I get the same error using NetBeans 3.5.1, ... The command the IDE is trying to execute - shown in the output window - is ...
    (comp.lang.java.softwaretools)
  • IRQL not less or equal (bugcheck 0x0A)
    ... If a kernel debugger is available get the stack backtrace. ... *** In order for this command to work properly, ... *** must point to .pdb files that have full type information. ...
    (microsoft.public.development.device.drivers)
  • Re: (MSVCRT.DLL): 0xC0000005: Access Violation
    ... That command will display a little bit more of what is going on. ... Debugger commands are very concise, and the seem random strings at first ... This posting is provided "AS IS" with no warranties, and confers no rights. ... >>> First chance exceptions are reported before any exception handling. ...
    (microsoft.public.vc.language)
  • Re: DRIVER_IRQL_NOT_LESS_OR_EQUAL error in IM Driver
    ... I am getting the error given below in my intermediate driver. ... If kernel debugger is available get stack backtrace. ... *** In order for this command to work properly, ... *** must point to .pdb files that have full type information. ...
    (microsoft.public.development.device.drivers)
  • Re: Microsoft: Making a simple process impossible to use in .NET 2.0
    ... adapter, you need the executescalar for that. ... What you want is a command on its own. ... The connection you can get very easy by getting that from whatever ... able to get a count of items contained in a SQL table by creating a ...
    (microsoft.public.dotnet.framework.adonet)