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
 

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

Back
Top