No, you do not need to delete and insert in order to update.
You can scan around for examples of how to do updates simply.
here's an example of a DataSet doing a Select from one database, and an
Update to another, using a single DataAdapter.
System.Data.Sql Client.SqlConne ction c1= new
System.Data.Sql Client.SqlConne ction(cstring1) ;
System.Data.Sql Client.SqlConne ction c2= new
System.Data.Sql Client.SqlConne ction(cstring2) ;
string strSelect="SELE CT ix, Created, [Last Updated], Headline, Dept FROM
blogposts WHERE blog_ix=@blog_i x AND CONVERT(Char(10 ),Created,102) =
@targdate ";
string strInsert="INSE RT INTO postbackups (ix, Saved, Headline, Dept)
VALUES (@ix, @Saved, @Headline, @Dept)";
System.Data.Sql Client.SqlDataA dapter da = new
System.Data.Sql Client.SqlDataA dapter();
da.SelectComman d= new System.Data.Sql Client.SqlComma nd(strSelect);
da.SelectComman d.Connection= c1;
da.UpdateComman d= new System.Data.Sql Client.SqlComma nd(strInsert);
da.UpdateComman d.Connection= c2;
da.SelectComman d.Parameters.Ad d("@blog_ix",
System.Data.Sql DbType.Int).Val ue= blog_ix;
da.SelectComman d.Parameters.Ad d("@targdate" ,
System.Data.Sql DbType.NVarChar ).Value= targdate;
da.UpdateComman d.Parameters.Ad d(new
System.Data.Sql Client.SqlParam eter("@ix", System.Data.Sql DbType.Int, 4,
"ix"));
da.UpdateComman d.Parameters.Ad d(new
System.Data.Sql Client.SqlParam eter("@Saved", System.Data.Sql DbType.DateTime ,
8, "Created")) ;
da.UpdateComman d.Parameters.Ad d(new
System.Data.Sql Client.SqlParam eter("@Headline ",
System.Data.Sql DbType.NVarChar , 50, "Headline") );
da.UpdateComman d.Parameters.Ad d(new
System.Data.Sql Client.SqlParam eter("@Dept", System.Data.Sql DbType.NVarChar ,
50, "Dept"));
da.TableMapping s.AddRange(new System.Data.Com mon.DataTableMa pping[] {
new System.Data.Com mon.DataTableMa pping("Table", "blogposts" , new
System.Data.Com mon.DataColumnM apping[] {
new System.Data.Com mon.DataColumnM apping("ix", "ix"),
new System.Data.Com mon.DataColumnM apping("blog_ix ", "blog_ix"),
new System.Data.Com mon.DataColumnM apping("Created ", "Created"),
new System.Data.Com mon.DataColumnM apping("Last Updated", "Last
Updated"),
new System.Data.Com mon.DataColumnM apping("Headlin e", "Headline") ,
new System.Data.Com mon.DataColumnM apping("Dept", "Dept")})}) ;
System.Data.Dat aSet ds= new System.Data.Dat aSet();
da.Fill(ds, "blogposts" );
// need to update the row so the DA does the insert
foreach (System.Data.Da taRow r in ds.Tables[0].Rows) {
r["Created"]= System.DateTime .Now; // update the row!
System.Console. WriteLine("rows tate: " + r.RowState);
}
da.Update(ds);
"Vijay Balki" <vi****@softe ch-usa.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
This might be a dumb question to ask. Can someone answer me with
patience.. When I have a typed or un-typed dataset, the only way I can update is like
below?
Dim con As New SqlConnection(C onnectionString )
con.Open()
Dim daProductsDS As New SqlDataAdapter( "Select * from ProductsDS", con)
Dim oCommandBuilder As New SqlCommandBuild er(daProductsDS )
daProductsDS.De leteCommand = oCommandBuilder .GetDeleteComma nd
daProductsDS.In sertCommand = oCommandBuilder .GetInsertComma nd
daProductsDS.Up dateCommand = oCommandBuilder .GetUpdateComma nd
'Apply the updates
daProductsDS.Up date(dsNorthwin d, "ProductsDS ")
Why do I have to delete and insert? Is the old fashion way of just
updating dead in DOT.NET? Please help me understand this. Why was this done away
with in dataset ? The other way is to manually use SQL statements to do
inserts/updates. But again I lose the power of using datasets.
Vijay