omessian

omessian

  • NA
  • 5
  • 0

Updating datasource from DataSet question

Oct 5 2004 10:54 AM
hi, hopefully this isn't a loaded question. i'm working on an app that uses a dataset who's tables are filled with some hybrid SELECT queries, meaning, the tables in the dataset are hybrids of mixed data from the datasource (SQL Server btw), or better, no single table in the dataset is a modeled copy of a table in the datasource. here's an example: //************************************************************ string sSQL = "SELECT tblA.pKeycol, tblA.val1, tblA.valX, tblB.valX, tblC.valX FROM tblA INNER JOIN tblB ON (tlbA.pKeyCol = tblB.fKeyCol), tblC WHERE tblA.pKeyCol = 'someValue' "; SqlConnection con = new SqlConnection("...some connection string"); SqlDataAdapter adpt = new SqlDataAdapter(sSQL, con); con.Open() DataSet ds = new DataSet(); adpt.Fill(ds, "tblHybrid"); // ... mess around with values in tblHybrid (add, change, delete, et al) // ... assume the changes are a.o.k., so update the datasource adpt.Update(ds); //************************************************************* for fun, say a one-to-many relationship exists between tblA and tblB as well as cascade update/delete constraints. so after making changes to the table in the dataset, what effect does a call to update() on this table do? is the SqlDataAdapter smart enough to figure out what goes where and how? does a scenario like this require that i build custom statements for the UPDATE, INSERT, and DELETE and attach the commands appropriately to the adapter? i guess for clarity it's possible for me to create other tables in the dataset that are replicas of what's in the SQL datasource -- and somehow reflect the changes here and then make a call to Update on these tables. this seems like 10-fold the amount of work necessary, however. sorry for the length of the question -- just getting my feet wet here. any thoughts, advice, suggestions? greatly appreciated, and thanks in advance!

Answers (2)