How to update a dataset which data come from two table

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?
 
B

Brock Allen

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"]);
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top