Table of Contents

Class DataManager

Namespace
Dynamicweb.Data
Assembly
Dynamicweb.Core.dll

Provides methods to update data on tables in Dynamicweb databases

public sealed class DataManager : IDisposable
Inheritance
DataManager
Implements
Inherited Members

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

Constructors

DataManager()

Initializes a new instance of the DataManager class.

public DataManager()

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

DataManager(bool)

Initializes a new instance of the DataManager class, which uses a transaction. When using DataManager with transactions, you should use Using, to be sure that the transaction is completed correctly

public DataManager(bool useTransaction)

Parameters

useTransaction bool

Methods

CreateDataSet(CommandBuilder)

Creates a DataSet with data returned by the passed CommandBuilder. Can only be called once per instance. Use multiple objects when your logic requires working with multiple connected datasets. Although the Finalize methods calls Dispose, thereby enabling the GC to clean up unmanaged code, call Dispose on your DataManager object as soon as your are done.

public DataSet CreateDataSet(CommandBuilder builder)

Parameters

builder CommandBuilder

The Dynamicweb.Data.DataManager.commandBuilder specifying the data to return in dataset

Returns

DataSet

A connected DataSet instance with data.

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

Remarks

Connects to the default database. Dynamic.mdb in /Database if the solution is running MS Access, or the SQL-Server database if the solution is running MS SQL-Server.

CreateDataSet(CommandBuilder, bool)

Creates a DataSet with data returned by the passed CommandBuilder. Can only be called once per instance. Use multiple objects when your logic requires working with multiple connected datasets. Although the Finalize methods calls Dispose, thereby enabling the GC to clean up unmanaged code, call Dispose on your DataManager object as soon as your are done.

public DataSet CreateDataSet(CommandBuilder builder, bool withSchema)

Parameters

builder CommandBuilder

The Dynamicweb.Data.DataManager.commandBuilder specifying the data to return in dataset

withSchema bool

Set to true if the returned dataset should contain schema information on table names, column names and types etc.

Returns

DataSet

A connected DataSet instance with data.

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

Remarks

Connects to the default database. Dynamic.mdb in /Database if the solution is running MS Access, or the SQL-Server database if the solution is running MS SQL-Server.

CreateDataSet(CommandBuilder, string)

Creates a DataSet with data returned by the passed CommandBuilder. Can only be called once per instance. Use multiple objects when your logic requires working with multiple connected datasets. Although the Finalize methods calls Dispose, thereby enabling the GC to clean up unmanaged code, call Dispose on your DataManager object as soon as your are done.

public DataSet CreateDataSet(CommandBuilder builder, string database)

Parameters

builder CommandBuilder

The Dynamicweb.Data.DataManager.commandBuilder specifying the data to return in dataset

database string

Name of the MS Access database to get the data from (I.e. "Access.mdb" in /Database directory). Ignored if solution is running MS SQL-Server

Returns

DataSet

A connected DataSet instance with data.

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

Remarks

Connects to the default database. Dynamic.mdb in /Database if the solution is running MS Access, or the SQL-Server database if the solution is running MS SQL-Server.

CreateDataSet(CommandBuilder, string, bool)

Creates a DataSet with data returned by the passed CommandBuilder. Can only be called once per instance. Use multiple objects when your logic requires working with multiple connected datasets. Although the Finalize methods calls Dispose, thereby enabling the GC to clean up unmanaged code, call Dispose on your DataManager object as soon as your are done.

public DataSet CreateDataSet(CommandBuilder builder, string database, bool withSchema)

Parameters

builder CommandBuilder

The Dynamicweb.Data.DataManager.commandBuilder specifying the data to return in dataset

database string

Name of the MS Access database to get the data from (I.e. "Access.mdb" in /Database directory). Ignored if solution is running MS SQL-Server

withSchema bool

Set to true if the returned dataset should contain schema information on table names, column names and types etc.

Returns

DataSet

A connected DataSet instance with data.

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

Remarks

Connects to the default database. Dynamic.mdb in /Database if the solution is running MS Access, or the SQL-Server database if the solution is running MS SQL-Server.

CreateDataSet(string)

Creates a DataSet with data returned by the passed SQL statement. Can only be called once per instance. Use multiple objects when your logic requires working with multiple connected datasets. Although the Finalize methods calls Dispose, thereby enabling the GC to clean up unmanaged code, call Dispose on your DataManager object as soon as your are done.

public DataSet CreateDataSet(string sql)

Parameters

sql string

The SQL specifying the data to return in dataset

Returns

DataSet

A connected DataSet instance with data.

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

Remarks

Connects to the default database. Dynamic.mdb in /Database if the solution is running MS Access, or the SQL-Server database if the solution is running MS SQL-Server.

CreateDataSet(string, bool)

Creates a DataSet with data returned by the passed SQL statement from the specified database. Can only be called once per instance. Use multiple objects when your logic requires working with multiple connected datasets. Although the Finalize methods calls Dispose, thereby enabling the GC to clean up unmanaged code, call Dispose on your DataManager object as soon as your are done.

public DataSet CreateDataSet(string sql, bool withSchema)

Parameters

sql string

The SQL specifying the data to return in DataSet

withSchema bool

Set to true if the returned dataset should contain schema information on table names, column names and types etc.

Returns

DataSet

A connected DataSet instance with data.

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

CreateDataSet(string, bool, Dictionary<string, Tuple<object, DbType>>?)

Creates a DataSet with data returned by the passed SQL statement from the specified database. Can only be called once per instance. Use multiple objects when your logic requires working with multiple connected datasets. Although the Finalize methods calls Dispose, thereby enabling the GC to clean up unmanaged code, call Dispose on your DataManager object as soon as your are done.

public DataSet CreateDataSet(string sql, bool withSchema, Dictionary<string, Tuple<object, DbType>>? sqlParams)

Parameters

sql string

The SQL specifying the data to return in DataSet

withSchema bool

Set to true if the returned dataset should contain schema information on table names, column names and types etc.

sqlParams Dictionary<string, Tuple<object, DbType>>

Command parameters dictionary with key as a param name and value of tuple(param value, param db type)

Returns

DataSet

A connected DataSet instance with data.

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases unmanaged and - optionally - managed resources

public void Dispose(bool disposeManagedObjects)

Parameters

disposeManagedObjects bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

~DataManager()

Allows an object to attempt to free resources and perform other cleanup operations before the object is reclaimed by garbage collection.

protected ~DataManager()

GetAddedIdentityKey()

The function returns the identity of the last added row to the database

public int GetAddedIdentityKey()

Returns

int

The identity of the last added row

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

Remarks

Returns an integer - this method will only work on tables with a primary key of type identity (SQL-Server), or Auto (MS-Access)

IsDisposed()

If the object is disposed this function throws an exception, otherwise the function returns false.

public bool IsDisposed()

Returns

bool

Returns false if the object has not been disposed.

Update(DataSet)

Updates the dataset.

public void Update(DataSet dataSet)

Parameters

dataSet DataSet

The dataset with changes to update.

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}

Update(DataSet, bool)

Updates the data set.

public void Update(DataSet dataSet, bool acceptChangesDuringFill)

Parameters

dataSet DataSet

The dataset with changes to update.

acceptChangesDuringFill bool

Indicating whether AcceptChanges is called on a DataRow after it is added to the DataTable during any of the Fill operations.

Examples

using System;
using System.Data;

namespace Dynamicweb.Data.Examples
{
    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);
                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"] = 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;
        }
    }
}
To top