DataSets & DataAdapters

Z

Z D

Hello,

here's the situation:

I have a query that returns 2 columns of data from a table. This data is
loaded into a typed dataset (DS).

I display each column's data in a text-box in ASP.NET.

Now, I dont want to have to save the DS or its corresponding dataadapter in
session or viewstate.

So, once the page is done, I loose the corresponding DS and DA. That's OK
because I have viewstate enabled on the textboxes that's storing the data so
it will be persisted across postbacks that may be generated elsewhere on the
page.

Now, if the user modify's the textboxes and hits the save button, I
obviously want to update this info in the db.

The problem is that i dont have the DA or typed DS anymore, so, I
instantiate new ones, add a new row to the DS, and then send it to the DA to
update it.

The problem now is that the DA doesnt realize that this row already exists
in the database! So, instead of doing an update, it does in insert!! :(

How do I get around this problem without persisting the DS in
viewstate/session???

I've even tried storing the PK value and setting it on the new DS so that
hopefully the DA would recognize that the row already exists.... no such
luck :(

So is there any way for me to "trick" the DS into thinking that this is a
row that already exists? If I persist the DS in session/viewstate then it
works fine... so where/how does it track this information? Maybe I can set
it manually so that the DA will know to do an update instead of an
insert....

any suggestions? comments? I would appreciate some help.

thanks:)
-ZD
 
P

Peter Bromberg [C# MVP]

Sounds like you've kinda boxed yourself into a corner.
Why not use a stored procedure to do the insert and forget about DataSets /
DataAdapters?
 
Z

Z D

Peter,

It seems much easier to use DataSet/Adapter because it takes care of all the
optimistic concurrency and the generation of the insert/update/delete
commands automatically. SOO many fewer stored procs that I need to write,
but not at the expense of having to maintain bloated DataSets in
viewstate/session... that would just kill the performance of my
memory-starved webserver to begin with!

I've always used stored proc's in the past to do this type of stuff, but
I've been hearing so much about DS/DA's that I figured I'd give it a shot if
it makes my life easier.

I think I might have figured out a way to get it to do an update instead of
an insert. Still in the process of testing to make sure though.

-Zane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top