RE: DataSets & DataAdapters

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Bill Borg (anonymous_at_discussions.microsoft.com)
Date: 03/19/04


Date: Thu, 18 Mar 2004 18:46:06 -0800

P.S. As an aside, since you don't want the dataset anyway, to load the textboxes you might consider using a datareader instead; it's more efficient than a dataset when you don't want/need to hang onto the data.
     
     ----- Bill Borg wrote: -----
     
     The info is tracked in Datarow.Rowstate (e.g. Added, Modified, Deleted, etc.), but that's a readonly property. I don't know all the particulars in your case, but one thing for sure you can do: skip using the DS and the DA on update. Afaik, the DA is just setting a filter on rowstate to find all the rows that have changed, then calling the appropriate InsertCommand, UpdateCommand, or DeleteCommand as necessary. No reason you can't do this yourself by creating your own connection, moving your values into the UpdateCommand string, and executing SQLNonQuery.
          
          ----- Z D wrote: -----
          
          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
          
          
          
          


Quantcast