Dynamicweb 8 Documentation
Update(DataSet) Method
Example 

The dataset with changes to update.
Updates the dataset.
Syntax
'Declaration
 
Public Overloads Sub Update( _ 
   ByVal dataset As DataSet _ 
) 
public void Update( 
   DataSet dataset 
)

Parameters

dataset
The dataset with changes to update.
Example
Updating data in the databaseUpdating data in the database
using System.Data;

namespace Dynamicweb.Examples.CSharp
{
class DataManagerSample
{
    public int Save(int id)
    {
        //Create a new datamanager instance
        using (var dtm = new DataManager())
        {
            //Create a dataset with zero, one or more rows to update.
            var ds = dtm.CreateDataSet("SELECT * FROM UrlPath WHERE UrlPathID=" + id, "Dynamic.mdb");
            DataRow row;

            //If the id is 0, there will be no records in the returned dataset
            if (id == 0)
            {
                //Add a new row to the table in the dataset
                row = ds.Tables[0].NewRow();
                ds.Tables[0].Rows.Add(row);
                //Set column values that only needs to be set on new rows
                row["UrlPathCreated"] = System.DateTime.Now;
            }
            else
            {
                //We had a record in the table
                row = ds.Tables[0].Rows[0];
            }

            //Update the column values
            row["UrlPathPath"] = "Contact";
            row["UrlPathRedirect"] = "Default.aspx?ID=1";
            row["UrlPathStatus"] = 301;
            row["UrlPathUpdated"] = System.DateTime.Now;
            row["UrlPathActive"] = true;

            //Pass the dataset to the datamanagers UpdateDataset method that will commit our changes to the database
            dtm.Update(ds);

            //If the id is 0, it was a new record - GetIdentity will return the id of the newest row added.
            if (id == 0)
            {
                id = dtm.GetAddedIdentityKey();
            }

            //Dispose the dataset
            ds.Dispose();
        }
        return id;
    }

}
}
Public Class DataManagerSample
    Public Function Save(ByVal id As Integer) As Integer
        'Create a new datamanager instance
        Using dtm As New DataManager
            'Create a dataset with zero, one or more rows to update.
            Dim ds As DataSet = dtm.CreateDataSet("SELECT * FROM UrlPath WHERE UrlPathID=" & id, "Dynamic.mdb")
            Dim row As DataRow

            'If the id is 0, there will be no records in the returned dataset
            If id = 0 Then
                'Add a new row to the table in the dataset
                row = ds.Tables(0).NewRow()
                ds.Tables(0).Rows.Add(row)
                'Set column values that only needs to be set on new rows
                row("UrlPathCreated") = Now
            Else
                'We had a record in the table
                row = ds.Tables(0).Rows(0)
            End If

            'Update the column values
            row("UrlPathPath") = "Contact"
            row("UrlPathRedirect") = "Default.aspx?ID=1"
            row("UrlPathStatus") = 301
            row("UrlPathUpdated") = Now
            row("UrlPathActive") = True

            'Pass the dataset to the datamanagers UpdateDataset method that will commit our changes to the database
            dtm.Update(ds)

            'If the id is 0, it was a new record - GetIdentity will return the id of the newest row added.
            If id = 0 Then
                id = dtm.GetAddedIdentityKey()
            End If

            'Dispose the dataset
            ds.Dispose()
        End Using
        Return id
    End Function
End Class
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DataManager Class
DataManager Members
Overload List

Send Feedback