SqlDataAdapter, DataSet best way

  • Thread starter Thread starter vooose
  • Start date Start date
V

vooose

Consider a server executing

"SELECT * FROM Settings WHERE UserID=@UserID"

which is loaded into a DataSet and then we use dataSet.GetXML() to send
this to the requesting client. The client converts this back into a
DataSet and then we use a DataGrid control to show the data.

How does one get the information *back* into the server? The first part
is easy - GetXML() on the client dataSet and send to server - but it's
the next part that has got me.
That is, how to "load" the user specific rows back into the server
dataSet and then do a SqlDataAdapter.Update())
 
One quick option:
WHen user sends back the data.

1. Create an empty dataset with the structure

SELECT * FROM Settings where 1=2

2. Pull user data into another dataset.
3. Copy over the DataTable(s) from the user DataSet to the empty DataSet
4. Call update

Not pretty, but it is rather easy and allows using Update on the Empty
DataSet's DataAdapter.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Thanks for your reply Greg. It's your step 3 that is causing grief. I've
got two DataSets:

DataSet userSet;
and
DataSet emptySet;

and am copying via...

foreach(DataRow row in userSet.Tables[0].Rows)
emptySet.Tables[0].Rows.Add(row.ItemArray);

Unfortunately when you call emptySet.Update() it INSERT's the rows
instead of doing an UPDATE. I should mention that each row in Settings
has a SettingID which is the primary key. Even tho Settings.SettingID is
the same I can't seem to trick the emptySet into thinking it should
perform an UPDATE instead of an INSERT. Do you see what I am saying?

Regards
 
Back
Top