How to update a dataset which data come from two table

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I have a dataset with a datatable, which data is select from to table like

SELECT Categories.CategoryID, Categories.CategoryName,
Products.ProductID,
Products.ProductName
FROM Categories INNER JOIN
Products ON Categories.CategoryID =
Products.CategoryID

I only want to update Products table

but the dataAdapter can't build update command.
How can do that?
 
Either write the Sql yourself via SqlConnection and SqlCommand, or you can
use the SqlCommandBuilder:

SqlDataAdapter da = new SqlDataAdapter("select * from table", connString);
DataSet ds = new DataSet();
da.Fill(ds, "MyTable");

ds.Tables["MyTable"].Rows[0]["SomeColumn"] = "NewValue";

SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(ds.Tables["MyTable"]);

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Back
Top