update db with modified column in dataset with existing connection

  • Thread starter Thread starter Zeng
  • Start date Start date
Z

Zeng

Hello,

I have a dataset with just one row and an existing open connection. The
datarow contains some changes. Would someone know an efficient way in
terms of performance to do this? Thanks!!
 
Oh, one more thing, and an existing transaction that the update must be
executed within.

Thanks!
 
Can't you just fire the Update method of the DataAdapter? Also, if you are
only going to ever have one row in your dataset, why do you want to leave
your connection open?
 
Basically I had other updates needs to be done from other datasets, that is
why I have the connection open.

Can't just fire the Update method of the DataAdapter because
1) I need to assign the connection to the update, looks like I can only do
that by creating an update command. This is not good because...
2) Creating update command requires tracking down which fields have been
modified to setup the parameter list. And this is not good because...
3) Tracking down which fields have been modified looks redundant to me
because the dataset knows exactly which fields have been changed.
 
Hi Zeng,

Zeng said:
Basically I had other updates needs to be done from other datasets, that is
why I have the connection open.

Can't just fire the Update method of the DataAdapter because
1) I need to assign the connection to the update, looks like I can only do
that by creating an update command. This is not good because...

You can freely assign a connection to a command object by setting its
Connection property.
(Example: adapter.UpdateCommand.Connection = conn)

2) Creating update command requires tracking down which fields have been
modified to setup the parameter list. And this is not good because...
3) Tracking down which fields have been modified looks redundant to me
because the dataset knows exactly which fields have been changed.

Actually not. If you are executing parametrized command, it is parsed only
once on the server.
Thus all the next calls will be faster.
Of course, if it parameters can be huge (network traffic) it is not that
fast anymore :)
 
But I would like to avoid setting up parameters myself because it requires
maintaining the list of parameters or list of names of the modified fields.
Since dataset knows which fields have been modified I hope there is a way to
pull an update command from dataset or just the parameter list from it so I
can just assign it to the update command.
 
Hi Zeng,

You can build the adapter at design time (right click on adapter, configure
adapter).
It will create all the necessary code for you.
 
Back
Top