Class DataManager
- Namespace
- Dynamicweb.Data
- Assembly
- Dynamicweb.Core.dll
Provides methods to update data on tables in Dynamicweb databases
- Inheritance
-
Data
Manager
- 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 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;
}
}
}
DataManager(bool)
Initializes a new instance of the Data
Parameters
useTransaction
bool
Methods
CreateDataSet(CommandBuilder)
Creates a Data
Parameters
builder
CommandBuilder The Dynamicweb.
Data. specifying the data to return in datasetData Manager. command Builder
Returns
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 Data
Parameters
builder
CommandBuilder The Dynamicweb.
Data. specifying the data to return in datasetData Manager. command Builder withSchema
boolSet to true if the returned dataset should contain schema information on table names, column names and types etc.
Returns
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 Data
Parameters
builder
CommandBuilder The Dynamicweb.
Data. specifying the data to return in datasetData Manager. command Builder database
stringName 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
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 Data
Parameters
builder
CommandBuilder The Dynamicweb.
Data. specifying the data to return in datasetData Manager. command Builder database
stringName 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
boolSet to true if the returned dataset should contain schema information on table names, column names and types etc.
Returns
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 Data
Parameters
sql
stringThe SQL specifying the data to return in dataset
Returns
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 Data
Parameters
sql
stringThe SQL specifying the data to return in Data
Set withSchema
boolSet to true if the returned dataset should contain schema information on table names, column names and types etc.
Returns
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 Data
public DataSet CreateDataSet(string sql, bool withSchema, Dictionary<string, Tuple<object, DbType>>? sqlParams)
Parameters
sql
stringThe SQL specifying the data to return in Data
Set withSchema
boolSet 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
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.
Dispose(bool)
Releases unmanaged and - optionally - managed resources
Parameters
disposeManagedObjects
booltrue
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.
GetAddedIdentityKey()
The function returns the identity of the last added row to the database
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.
Returns
- bool
Returns false if the object has not been disposed.
Update(DataSet)
Updates the 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.
Parameters
dataSet
DataSet The dataset with changes to update.
acceptChangesDuringFill
boolIndicating 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;
}
}
}