Class Database
- Namespace
- Dynamicweb.Data
- Assembly
- Dynamicweb.Core.dll
This class contains functions to handle database connection and interaction.
Database | Function to call |
---|---|
Create a database connection | Create |
Create a DataReader | Create |
Create a DataTable | Create |
Create a DataSet | Create |
Execute a non-query | Execute |
Create a CommandBuilder | Create |
Create a DataAdapter | Create |
- Inheritance
-
Database
- Inherited Members
Examples
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateConnection
{
public void ConnectToDatabase()
{
//Create a connection to default database
using (var myConnection = Database.CreateConnection())
{
//Create a command object from the connection
using (var myCommand = myConnection.CreateCommand())
{
//Create a DataAdapter
var daAdapter = Database.CreateAdapter();
//Prepare command object
myCommand.CommandText = "SELECT TOP 1 * FROM Page";
daAdapter.SelectCommand = myCommand;
//Fill a dataset
var myDataSet = new DataSet();
daAdapter.Fill(myDataSet);
}
}
//Create a connection to another database in /Database folder when running Access
using (var myConnection = Database.CreateConnection())
{
//Do stuff witht the connection
}
var con = (System.Data.SqlClient.SqlConnection)Database.CreateConnection();
}
}
}
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Properties
ConnectionString
Gets the connection string. ONLY MSSQL!
Property Value
- string
The connection string.
LocalAddress
Gets or sets the local alternative ip address.
Property Value
- string
The local addr.
Methods
AddBooleanParam(IDbCommand, string, bool)
Adds boolean parameter to SQL statement.
Parameters
cmd
IDbCommand The IDbCommand to add the parameter to
name
stringThe name of the System.Data.IDataParameter.
value
boolThe value of the parameter.
AddDateTimeParam(IDbCommand, string, DateTime)
Adds DateTime parameter to SQL statement.
Parameters
cmd
IDbCommand The IDbCommand to add the parameter to
name
stringThe name of the System.Data.IDataParameter.
value
DateTime The value of the parameter.
AddDoubleParam(IDbCommand, string, double)
Adds double parameter to SQL statement.
Parameters
cmd
IDbCommand The IDbCommand to add the parameter to
name
stringThe name of the System.Data.IDataParameter.
value
doubleThe value of the parameter.
AddInt16Param(IDbCommand, string, short)
Adds Int16 parameter to SQL statement.
Parameters
cmd
IDbCommand The IDbCommand to add the parameter to
name
stringThe name of the System.Data.IDataParameter.
value
shortThe value of the parameter.
AddInt32Param(IDbCommand, string, int)
Adds Int32 parameter to SQL statement.
Parameters
cmd
IDbCommand The IDbCommand to add the parameter to
name
stringThe name of the System.Data.IDataParameter.
value
intThe value of the parameter.
AddStringParam(IDbCommand, string, string?)
Adds string parameter to SQL statement.
Parameters
cmd
IDbCommand The IDbCommand to add the parameter to
name
stringThe name of the System.Data.IDataParameter.
value
stringThe value of the parameter.
ColumnExists(IDataReader, string)
Checks if a columns the exists in a given datareader.
Parameters
reader
IDataReader The datareader.
columnName
stringName of the column.
Returns
- bool
true
if the column exists; otherwisefalse
CopyRow(IDbCommand, IDictionary<string, object>)
Copies a row and replaces some values in the new row
Parameters
command
IDbCommand The IDb
Command to select the row to copynewValues
IDictionary<string, object>A dictionary of (column name, new value). These values will be set on the new row
Remarks
If more rows match the query, only the first will be copied. See CopyRow(string, Dictionary<string, Tuple<object, DbType>>, IDictionary<string, object>) for example
CopyRow(string, Dictionary<string, Tuple<object, DbType>>, IDictionary<string, object>)
Copies a row and replaces some values in the new row
public static void CopyRow(string selectSql, Dictionary<string, Tuple<object, DbType>> sqlParams, IDictionary<string, object> newValues)
Parameters
selectSql
stringThe SQL command text to select the row to copy
sqlParams
Dictionary<string, Tuple<object, DbType >>Command parameters dictionary with key as a param name and value of tuple(param value, param db type)
newValues
IDictionary<string, object>A dictionary of (column name, new value). These values will be set on the new row
Remarks
If more rows match the SQL, only the first will be copied
CreateAdapter()
Creates a DataAdapter based on the database type of the solution.
Returns
- IDb
Data Adapter A Sql
Data or OleAdapter DbData depending on the database type.Adapter
Examples
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateConnection
{
public void ConnectToDatabase()
{
//Create a connection to default database
using (var myConnection = Database.CreateConnection())
{
//Create a command object from the connection
using (var myCommand = myConnection.CreateCommand())
{
//Create a DataAdapter
var daAdapter = Database.CreateAdapter();
//Prepare command object
myCommand.CommandText = "SELECT TOP 1 * FROM Page";
daAdapter.SelectCommand = myCommand;
//Fill a dataset
var myDataSet = new DataSet();
daAdapter.Fill(myDataSet);
}
}
//Create a connection to another database in /Database folder when running Access
using (var myConnection = Database.CreateConnection())
{
//Do stuff witht the connection
}
var con = (System.Data.SqlClient.SqlConnection)Database.CreateConnection();
}
}
}
Remarks
The type of the DataAdapter is based on the database type set up for the current solution.
CreateAdapter(CommandBuilder)
Creates a DataAdapter based on the database type of the command.
Parameters
commandBuilder
CommandBuilder The Command
Builder to create the IDbData from.Adapter
Returns
Examples
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateConnection
{
public void ConnectToDatabase()
{
//Create a connection to default database
using (var myConnection = Database.CreateConnection())
{
//Create a command object from the connection
using (var myCommand = myConnection.CreateCommand())
{
//Create a DataAdapter
var daAdapter = Database.CreateAdapter();
//Prepare command object
myCommand.CommandText = "SELECT TOP 1 * FROM Page";
daAdapter.SelectCommand = myCommand;
//Fill a dataset
var myDataSet = new DataSet();
daAdapter.Fill(myDataSet);
}
}
//Create a connection to another database in /Database folder when running Access
using (var myConnection = Database.CreateConnection())
{
//Do stuff witht the connection
}
var con = (System.Data.SqlClient.SqlConnection)Database.CreateConnection();
}
}
}
CreateAdapter(IDbCommand)
Creates a DataAdapter based on the database type of the command.
Parameters
command
IDbCommand The IDb
Command to create the IDbData from.Adapter
Returns
Examples
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateConnection
{
public void ConnectToDatabase()
{
//Create a connection to default database
using (var myConnection = Database.CreateConnection())
{
//Create a command object from the connection
using (var myCommand = myConnection.CreateCommand())
{
//Create a DataAdapter
var daAdapter = Database.CreateAdapter();
//Prepare command object
myCommand.CommandText = "SELECT TOP 1 * FROM Page";
daAdapter.SelectCommand = myCommand;
//Fill a dataset
var myDataSet = new DataSet();
daAdapter.Fill(myDataSet);
}
}
//Create a connection to another database in /Database folder when running Access
using (var myConnection = Database.CreateConnection())
{
//Do stuff witht the connection
}
var con = (System.Data.SqlClient.SqlConnection)Database.CreateConnection();
}
}
}
Remarks
The type of the DataAdapter is based on the IDb
CreateCommandBuilder(ref IDbDataAdapter)
Creates a CommandBuilder based for the specified DataAdapters.
Parameters
adapter
IDbData Adapter An existing DataAdapter.
Returns
- Db
Command Builder A SqlCommandBuilder.
Remarks
A CommandBuilder automatically generates Insert, Update and Delete commands based on a DataAdapters Select command
CreateConnection()
Creates and opens a database connection to the default database
Returns
- IDb
Connection A Database Connection (a IDbConnection object). The connection is connected to /Database/Dynamic.mdb if the solution runs on MS Access or to the SQL Server database specified in database setup (/Files/GlobalSettings.aspx) if the solution runs on MS SQL-Server.
Examples
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateConnection
{
public void ConnectToDatabase()
{
//Create a connection to default database
using (var myConnection = Database.CreateConnection())
{
//Create a command object from the connection
using (var myCommand = myConnection.CreateCommand())
{
//Create a DataAdapter
var daAdapter = Database.CreateAdapter();
//Prepare command object
myCommand.CommandText = "SELECT TOP 1 * FROM Page";
daAdapter.SelectCommand = myCommand;
//Fill a dataset
var myDataSet = new DataSet();
daAdapter.Fill(myDataSet);
}
}
//Create a connection to another database in /Database folder when running Access
using (var myConnection = Database.CreateConnection())
{
//Do stuff witht the connection
}
var con = (System.Data.SqlClient.SqlConnection)Database.CreateConnection();
}
}
}
Remarks
The returned IDbConnection instance is either a Sql
CreateDataReader(CommandBuilder)
Creates a DataReader by creating a IDbCommand with the CommandBuilder and sending it to the Connection and build an IDataReader.
Parameters
commandBuilder
CommandBuilder The CommandBuilder specifying the data to return in the DataReader
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(CommandBuilder, IDbConnection)
Creates a DataReader by creating a IDbCommand with the CommandBuilder and sending it to the Connection and build an IDataReader.
Parameters
commandBuilder
CommandBuilder The CommandBuilder specifying the data to return in the DataReader
connection
IDbConnection Existing database connection. The connection will remain open upon the completion.
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(CommandBuilder, IDbConnection, IDbTransaction)
Creates a DataReader by creating a IDbCommand with the CommandBuilder and sending it to the Connection and build an IDataReader.
public static IDataReader CreateDataReader(CommandBuilder commandBuilder, IDbConnection connection, IDbTransaction transaction)
Parameters
commandBuilder
CommandBuilder The CommandBuilder specifying the data to return in the DataReader
connection
IDbConnection Existing database connection. The connection will remain open upon the completion.
transaction
IDbTransaction The transaction.
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(CommandBuilder, IDbConnection, int)
Creates a DataReader by creating a IDbCommand with the CommandBuilder and sending it to the Connection and build an IDataReader.
public static IDataReader CreateDataReader(CommandBuilder commandBuilder, IDbConnection connection, int commandTimeout)
Parameters
commandBuilder
CommandBuilder The CommandBuilder specifying the data to return in the DataReader
connection
IDbConnection Existing database connection. The connection will remain open upon the completion.
commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(CommandBuilder, int)
Creates a DataReader by creating a IDbCommand with the CommandBuilder and sending it to the Connection and build an IDataReader.
Parameters
commandBuilder
CommandBuilder The CommandBuilder specifying the data to return in the DataReader
commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(IDbCommand, CommandBehavior)
Creates a DataReader by sending an IDbCommand to the Connection and build an IDataReader.
Parameters
command
IDbCommand The Command specifying the data to return in the DataReader
behavior
CommandBehavior The CommandBehavior to be used when executing the IDbCommand.
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(string)
Creates a DataReader by sending the sql to the Connection and build an IDataReader.
Parameters
sql
stringThe SQL specifiyng the data to return in the DataReader
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(string, Dictionary<string, Tuple<object, DbType>>)
Creates a DataReader by sending the sql to the Connection and build an IDataReader.
public static IDataReader CreateDataReader(string sql, Dictionary<string, Tuple<object, DbType>> sqlParams)
Parameters
sql
stringThe SQL specifiyng the data to return in the DataReader
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
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(string, IDbConnection)
Creates a DataReader by sending the sql to the Connection and build an IDataReader.
Parameters
sql
stringThe SQL specifiyng the data to return in the DataReader
connection
IDbConnection Existing database connection.
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(string, IDbConnection, IDbTransaction)
Creates a DataReader by sending the sql to the Connection and build an IDataReader.
public static IDataReader CreateDataReader(string sql, IDbConnection connection, IDbTransaction transaction)
Parameters
sql
stringThe SQL specifiyng the data to return in the DataReader
connection
IDbConnection Existing database connection.
transaction
IDbTransaction Existing transaction on the given connection.
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(string, IDbConnection, int)
Creates a DataReader by sending the sql to the Connection and build an IDataReader.
public static IDataReader CreateDataReader(string sql, IDbConnection connection, int commandTimeout)
Parameters
sql
stringThe SQL specifiyng the data to return in the DataReader
connection
IDbConnection Existing database connection.
commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds. 0 Indicates infinite.
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataReader(string, int)
Creates a DataReader by sending the sql to the Connection and build an IDataReader.
Parameters
sql
stringThe SQL specifiyng the data to return in the DataReader
commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds. 0 indicates infinite.
Returns
- IData
Reader Datareader instance - OleDBReader for Access solutions and SqlDbReader for SQl-Server based solutions.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataReader
{
public void DataReaderSample()
{
//Create a DataReader on the default database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM Page"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["PageID"]);
}
}
//Create a DataReader on alternate database
using (var myDr = Database.CreateDataReader("SELECT TOP 10 * FROM AccessUser"))
{
while (myDr.Read())
{
var pageId = Converter.ToInt32(myDr["AccessUserID"]);
}
}
}
}
}
Remarks
The underlying connection will close itself after the reader is closed and disposed.
CreateDataSet(CommandBuilder)
Creates a Data
Parameters
commandBuilder
CommandBuilder The Command
Builder specifying the query to execute and data to return in the DataSet .
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateDataSet
{
public void DataSetSample()
{
//Create dataset on the default database
var myDataSet = Database.CreateDataSet("SELECT TOP 10 * FROM Page");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create dataset on alternate database
var myDataset2 = Database.CreateDataSet("SELECT TOP 10 * FROM AccessUser");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected Data
CreateDataSet(CommandBuilder, bool)
Creates a Data
Parameters
commandBuilder
CommandBuilder The Command
Builder specifying the query to execute and data to return in the DataSet .withSchema
boolSet to true if the returned dataset should contain schema information on table names, column names and types etc.
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateDataSet
{
public void DataSetSample()
{
//Create dataset on the default database
var myDataSet = Database.CreateDataSet("SELECT TOP 10 * FROM Page");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create dataset on alternate database
var myDataset2 = Database.CreateDataSet("SELECT TOP 10 * FROM AccessUser");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected Data
CreateDataSet(CommandBuilder, IDbConnection)
Creates a Data
Parameters
commandBuilder
CommandBuilder The Command
Builder specifying the query to execute and data to return in the DataSet .connection
IDbConnection Existing database connection. The connection will remain open upon the completion.
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateDataSet
{
public void DataSetSample()
{
//Create dataset on the default database
var myDataSet = Database.CreateDataSet("SELECT TOP 10 * FROM Page");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create dataset on alternate database
var myDataset2 = Database.CreateDataSet("SELECT TOP 10 * FROM AccessUser");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected Data
CreateDataSet(CommandBuilder, IDbConnection, bool)
Creates a Data
public static DataSet CreateDataSet(CommandBuilder commandBuilder, IDbConnection connection, bool withSchema)
Parameters
commandBuilder
CommandBuilder The Command
Builder specifying the query to execute and data to return in the DataSet .connection
IDbConnection Existing database connection. The connection will remain open upon the completion.
withSchema
boolSet to true if the returned dataset should contain schema information on table names, column names and types etc.
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateDataSet
{
public void DataSetSample()
{
//Create dataset on the default database
var myDataSet = Database.CreateDataSet("SELECT TOP 10 * FROM Page");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create dataset on alternate database
var myDataset2 = Database.CreateDataSet("SELECT TOP 10 * FROM AccessUser");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected Data
CreateDataSet(CommandBuilder, IDbConnection, IDbTransaction)
Creates a Data
public static DataSet CreateDataSet(CommandBuilder commandBuilder, IDbConnection connection, IDbTransaction transaction)
Parameters
commandBuilder
CommandBuilder The Command
Builder specifying the query to execute and data to return in the DataSet .connection
IDbConnection Existing database connection. The connection will remain open upon the completion.
transaction
IDbTransaction The transaction.
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateDataSet
{
public void DataSetSample()
{
//Create dataset on the default database
var myDataSet = Database.CreateDataSet("SELECT TOP 10 * FROM Page");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create dataset on alternate database
var myDataset2 = Database.CreateDataSet("SELECT TOP 10 * FROM AccessUser");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected Data
CreateDataSet(CommandBuilder, IDbConnection, IDbTransaction?, bool)
Creates a Data
public static DataSet CreateDataSet(CommandBuilder commandBuilder, IDbConnection connection, IDbTransaction? transaction, bool withSchema)
Parameters
commandBuilder
CommandBuilder The Command
Builder specifying the query to execute and data to return in the DataSet .connection
IDbConnection Existing database connection. The connection will remain open upon the completion.
transaction
IDbTransaction The transaction.
withSchema
boolSet to true if the returned dataset should contain schema information on table names, column names and types etc.
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateDataSet
{
public void DataSetSample()
{
//Create dataset on the default database
var myDataSet = Database.CreateDataSet("SELECT TOP 10 * FROM Page");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create dataset on alternate database
var myDataset2 = Database.CreateDataSet("SELECT TOP 10 * FROM AccessUser");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected Data
CreateDataSet(string)
Creates a Data
Parameters
sql
stringThe SQL specifiyng the data to return in dataset
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateDataSet
{
public void DataSetSample()
{
//Create dataset on the default database
var myDataSet = Database.CreateDataSet("SELECT TOP 10 * FROM Page");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create dataset on alternate database
var myDataset2 = Database.CreateDataSet("SELECT TOP 10 * FROM AccessUser");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected dataset, no updates are possible. If you want to obtain an updatable dataset use the Data
CreateDataSet(string, Dictionary<string, Tuple<object, DbType>>)
Creates a Data
public static DataSet CreateDataSet(string sql, Dictionary<string, Tuple<object, DbType>> sqlParams)
Parameters
sql
stringThe SQL specifiyng the data to return in dataset
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 Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateDataSet
{
public void DataSetSample()
{
//Create dataset on the default database
var myDataSet = Database.CreateDataSet("SELECT TOP 10 * FROM Page");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create dataset on alternate database
var myDataset2 = Database.CreateDataSet("SELECT TOP 10 * FROM AccessUser");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected dataset, no updates are possible. If you want to obtain an updatable dataset use the Data
CreateDataSet(string, IDbConnection, IDbTransaction?)
Creates a Data
public static DataSet CreateDataSet(string sql, IDbConnection connection, IDbTransaction? transaction)
Parameters
sql
stringThe SQL specifiyng the data to return in dataset
connection
IDbConnection Existing database connection.
transaction
IDbTransaction The transaction.
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
public class DatabaseCreateDataSet
{
public void DataSetSample()
{
//Create dataset on the default database
var myDataSet = Database.CreateDataSet("SELECT TOP 10 * FROM Page");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create dataset on alternate database
var myDataset2 = Database.CreateDataSet("SELECT TOP 10 * FROM AccessUser");
//Loop rows in dataset
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected dataset, no updates are possible. If you want to obtain an updatable dataset use the Data
CreateDataTable(string)
Creates a Data
Parameters
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataTable
{
public void DataTableSample()
{
//Create DataTable on the default database
var myDataTable = Database.CreateDataTable("SELECT TOP 10 * FROM Page");
//Loop rows in DataTable
foreach (DataRow row in myDataTable.Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create DataTable on alternate database
DataTable myDataTable2 = Database.CreateDataTable("SELECT TOP 10 * FROM AccessUser");
//Loop rows in DataTable
foreach (DataRow row in myDataTable.Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
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.
Since this is a disconnected Data
CreateDataTable(string, IDbConnection)
Creates a Data
Parameters
sql
stringThe SQL specifiyng the data to return in Data
Table connection
IDbConnection Existing database connection.
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataTable
{
public void DataTableSample()
{
//Create DataTable on the default database
var myDataTable = Database.CreateDataTable("SELECT TOP 10 * FROM Page");
//Loop rows in DataTable
foreach (DataRow row in myDataTable.Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create DataTable on alternate database
DataTable myDataTable2 = Database.CreateDataTable("SELECT TOP 10 * FROM AccessUser");
//Loop rows in DataTable
foreach (DataRow row in myDataTable.Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected Data
CreateDataTable(string, IDbConnection, IDbTransaction?)
Creates a Data
public static DataTable CreateDataTable(string sql, IDbConnection connection, IDbTransaction? transaction)
Parameters
sql
stringThe SQL specifiyng the data to return in Data
Table connection
IDbConnection Existing database connection.
transaction
IDbTransaction Existing transaction on the given connection.
Returns
Examples
using Dynamicweb.Core;
using System.Data;
namespace Dynamicweb.Data.Examples
{
class DatabaseCreateDataTable
{
public void DataTableSample()
{
//Create DataTable on the default database
var myDataTable = Database.CreateDataTable("SELECT TOP 10 * FROM Page");
//Loop rows in DataTable
foreach (DataRow row in myDataTable.Rows)
{
var pageId = Converter.ToInt32(row["PageID"]);
}
//Create DataTable on alternate database
DataTable myDataTable2 = Database.CreateDataTable("SELECT TOP 10 * FROM AccessUser");
//Loop rows in DataTable
foreach (DataRow row in myDataTable.Rows)
{
var userId = Converter.ToInt32(row["AccessUserID"]);
}
}
}
}
Remarks
Since this is a disconnected Data
CreatePreparedAdapter(CommandBuilder, IDbConnection)
Creates a IDbcommandBuilder
.
The IDb
public static IDbDataAdapter CreatePreparedAdapter(CommandBuilder commandBuilder, IDbConnection connection)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the SELECT-query.connection
IDbConnection The IDb
Connection to the relevant database.
Returns
- IDb
Data Adapter A prepared IData
Adapter with Select-, Insert-, Update- and Delete commands.
CreatePreparedAdapter(CommandBuilder, IDbConnection, bool)
Creates a IDbcommandBuilder
.
The IDb
public static IDbDataAdapter CreatePreparedAdapter(CommandBuilder commandBuilder, IDbConnection connection, bool tryFillIdentity)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the SELECT-query.connection
IDbConnection The IDb
Connection to the relevant database.tryFillIdentity
boolBoolean value indicating whether the Identity column should be filled automatically or not. Default is
false
.
Returns
- IDb
Data Adapter A prepared IData
Adapter with Select-, Insert-, Update- and Delete commands.
CreatePreparedAdapter(CommandBuilder, IDbConnection, IDbTransaction)
Creates a IDbcommandBuilder
.
The IDb
public static IDbDataAdapter CreatePreparedAdapter(CommandBuilder commandBuilder, IDbConnection connection, IDbTransaction transaction)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the SELECT-query.connection
IDbConnection The IDb
Connection to the relevant database.transaction
IDbTransaction The IDb
Transaction to use when executing queries
Returns
- IDb
Data Adapter A prepared IData
Adapter with Select-, Insert-, Update- and Delete commands.
CreatePreparedAdapter(CommandBuilder, IDbConnection, IDbTransaction?, bool)
Creates a IDbcommandBuilder
.
The IDb
public static IDbDataAdapter CreatePreparedAdapter(CommandBuilder commandBuilder, IDbConnection connection, IDbTransaction? transaction, bool tryFillIdentity)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the SELECT-query.connection
IDbConnection The IDb
Connection to the relevant database.transaction
IDbTransaction The IDb
Transaction to use when executing queriestryFillIdentity
boolBoolean value indicating whether the Identity column should be filled automatically or not. Default is
false
.
Returns
- IDb
Data Adapter A prepared IData
Adapter with Select-, Insert-, Update- and Delete commands.
CreatePreparedAdapter(IDbCommand)
Creates a IDbcommand
.
The IDb
Parameters
command
IDbCommand The IDb
Command containing the SELECT-query.
Returns
- IDb
Data Adapter A prepared IData
Adapter with Select-, Insert-, Update- and Delete commands.
CreatePreparedAdapter(IDbCommand, bool)
Creates a IDbcommand
.
The IDb
Parameters
command
IDbCommand The IDb
Command containing the SELECT-query.tryFillIdentity
boolBoolean value indicating whether the Identity column should be filled automatically or not. Default is
false
.
Returns
- IDb
Data Adapter A prepared IData
Adapter with Select-, Insert-, Update- and Delete commands.
CreatePreparedAdapter(string, IDbConnection)
Creates a IDb
Parameters
selectSql
stringThe select SQL.
connection
IDbConnection The IDb
Connection to the relevant database.
Returns
CreatePreparedAdapter(string, IDbConnection, bool)
Creates a IDb
public static IDbDataAdapter CreatePreparedAdapter(string selectSql, IDbConnection connection, bool tryFillIdentity)
Parameters
selectSql
stringThe select SQL.
connection
IDbConnection The IDb
Connection to the relevant database.tryFillIdentity
boolBoolean value indicating whether the Identity column should be filled automatically or not. Default is
false
.
Returns
CreatePreparedAdapter(string, IDbConnection, IDbTransaction)
Creates a IDb
public static IDbDataAdapter CreatePreparedAdapter(string selectSql, IDbConnection connection, IDbTransaction transaction)
Parameters
selectSql
stringThe select SQL.
connection
IDbConnection The IDb
Connection to the relevant database.transaction
IDbTransaction The IDb
Transaction to use when executing queries
Returns
CreatePreparedAdapter(string, IDbConnection, IDbTransaction?, bool)
Creates a IDb
public static IDbDataAdapter CreatePreparedAdapter(string selectSql, IDbConnection connection, IDbTransaction? transaction, bool tryFillIdentity)
Parameters
selectSql
stringThe select SQL.
connection
IDbConnection The IDb
Connection to the relevant database.transaction
IDbTransaction The IDb
Transaction to use when executing queriestryFillIdentity
boolBoolean value indicating whether the Identity column should be filled automatically or not. Default is
false
.
Returns
EscapeForLikeStatement(string, bool)
Wrapes wildcard characters in to [] symbols.
Parameters
Returns
- string
String with wraped symbols.
ExecuteNonQuery(CommandBuilder)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.
Returns
- int
The number of rows affected.
ExecuteNonQuery(CommandBuilder, bool)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.useTransaction
boolIf set to
true
the query is executed in a transaction.
Returns
- int
The number of rows affected.
ExecuteNonQuery(CommandBuilder, bool, int)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
public static int ExecuteNonQuery(CommandBuilder commandBuilder, bool useTransaction, int commandTimeout)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.useTransaction
boolIf set to
true
the query is executed in a transaction.commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Returns
- int
The number of rows affected.
ExecuteNonQuery(CommandBuilder, IDbConnection)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.connection
IDbConnection Existing database connection to be reused. The connection will not be closed upon completion.
Returns
- int
The number of rows affected.
ExecuteNonQuery(CommandBuilder, IDbConnection, bool)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
public static int ExecuteNonQuery(CommandBuilder commandBuilder, IDbConnection connection, bool useTransaction)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.connection
IDbConnection Existing database connection to be reused. The connection will not be closed upon completion.
useTransaction
boolIf set to
true
the query is executed in a transaction.
Returns
- int
The number of rows affected.
ExecuteNonQuery(CommandBuilder, IDbConnection, bool, int)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
public static int ExecuteNonQuery(CommandBuilder commandBuilder, IDbConnection connection, bool useTransaction, int commandTimeout)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.connection
IDbConnection Existing database connection to be reused. The connection will not be closed upon completion.
useTransaction
boolIf set to
true
the query is executed in a transaction.commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Returns
- int
The number of rows affected.
ExecuteNonQuery(CommandBuilder, IDbConnection, IDbTransaction?)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
public static int ExecuteNonQuery(CommandBuilder commandBuilder, IDbConnection connection, IDbTransaction? transaction)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.connection
IDbConnection Existing database connection to be reused. The connection will not be closed upon completion.
transaction
IDbTransaction The transaction associated with the specified
connection
.
Returns
- int
The number of rows affected.
ExecuteNonQuery(CommandBuilder, IDbConnection, IDbTransaction?, int)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
public static int ExecuteNonQuery(CommandBuilder commandBuilder, IDbConnection connection, IDbTransaction? transaction, int commandTimeout)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.connection
IDbConnection Existing database connection to be reused. The connection will not be closed upon completion.
transaction
IDbTransaction The transaction associated with the specified
connection
.commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Returns
- int
The number of rows affected.
ExecuteNonQuery(CommandBuilder, IDbConnection, int)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
public static int ExecuteNonQuery(CommandBuilder commandBuilder, IDbConnection connection, int commandTimeout)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.connection
IDbConnection Existing database connection to be reused. The connection will not be closed upon completion.
commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Returns
- int
The number of rows affected.
ExecuteNonQuery(CommandBuilder, int)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Returns
- int
The number of rows affected.
ExecuteNonQuery(IDbCommand)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
command
IDbCommand The IDb
Command containing the query to execute.
Returns
- int
The number of rows affected.
ExecuteNonQuery(string)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
sql
stringThe SQL to execute against the database
Returns
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteNonQuery(string, bool)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
Returns
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteNonQuery(string, bool, IDbConnection)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
sql
stringThe SQL to execute against the database
transaction
boolif set to
true
[transaction].connection
IDbConnection Existing database connection.
Returns
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteNonQuery(string, Dictionary<string, Tuple<object, DbType>>)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
sql
stringThe SQL to execute against the database
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
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteNonQuery(string, IDbConnection)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
sql
stringThe SQL to execute against the database
connection
IDbConnection Existing database connection.
Returns
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteNonQuery(string, IDbConnection, IDbTransaction)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
sql
stringThe SQL to execute against the database
connection
IDbConnection Existing database connection.
transaction
IDbTransaction The transaction.
Returns
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteNonQuery(string, IDbConnection, IDbTransaction, int)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
public static int ExecuteNonQuery(string sql, IDbConnection connection, IDbTransaction transaction, int commandTimeout)
Parameters
sql
stringThe SQL to execute against the database
connection
IDbConnection Existing database connection.
transaction
IDbTransaction The transaction.
commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Returns
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteNonQuery(string, int)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
sql
stringThe SQL to execute against the database
commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Returns
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteNonQuery(string, int, bool)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
sql
stringThe SQL to execute against the database
commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
useTransaction
boolIf set to
true
the query is executed in a transaction.
Returns
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteNonQuery(string, int, bool, IDbConnection)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
public static int ExecuteNonQuery(string sql, int commandTimeout, bool useTransaction, IDbConnection connection)
Parameters
sql
stringThe SQL to execute against the database
commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
useTransaction
boolIf set to
true
the query is executed in a transaction.connection
IDbConnection Existing database connection.
Returns
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteNonQuery(string, int, IDbConnection)
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Parameters
sql
stringThe SQL to execute against the database
commandTimeout
intThe wait time before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
connection
IDbConnection Existing database connection.
Returns
- int
The number of rows affected.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteScalar(CommandBuilder)
Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.
Returns
- object
The first column of the first row in the resultset.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteScalar(CommandBuilder, IDbConnection?)
Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.connection
IDbConnection Existing database connection. The connection will remain open upon the completion.
Returns
- object
The first column of the first row in the resultset.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteScalar(CommandBuilder, IDbConnection, IDbTransaction?)
Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
public static object? ExecuteScalar(CommandBuilder commandBuilder, IDbConnection connection, IDbTransaction? transaction)
Parameters
commandBuilder
CommandBuilder The Command
Builder containing the query to execute.connection
IDbConnection Existing database connection. The connection will remain open upon the completion.
transaction
IDbTransaction The transaction associated with specified
connection
.
Returns
- object
The first column of the first row in the resultset.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteScalar(IDbCommand)
Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
Parameters
command
IDbCommand The IDb
Command containing the query to execute.
Returns
- object
The first column of the first row in the resultset.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteScalar(string)
Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
Parameters
sql
stringThe SQL to execute against the database
Returns
- object
The first column of the first row in the resultset.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
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.
ExecuteScalar(string, IDbConnection)
Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
Parameters
sql
stringThe SQL to execute against the database
connection
IDbConnection Existing database connection.
Returns
- object
The first column of the first row in the resultset.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
ExecuteScalar(string, IDbConnection, IDbTransaction?)
Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
public static object? ExecuteScalar(string sql, IDbConnection connection, IDbTransaction? transaction)
Parameters
sql
stringThe SQL to execute against the database
connection
IDbConnection Existing database connection.
transaction
IDbTransaction The transaction.
Returns
- object
The first column of the first row in the resultset.
Examples
using Dynamicweb.Core;
namespace Dynamicweb.Data.Examples
{
class DatabaseExecute
{
public void ExecuteSample()
{
//ExecuteScalar
var pageCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));
//ExecuteScalar on alternate database
var userCount = Converter.ToInt32(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"));
//ExecuteNonQuery
var numberOfPagesDeleted = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101");
//ExecuteNonQuery on alternate database
var numberOfUsersDeleted = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101");
}
}
}
GetAddedIdentityKey(ref DataRow, ref IDbConnection, int)
The function returns the identity of the last added row to the database
Parameters
row
DataRow The datarow to update.
connection
IDbConnection The connection used to update the datarow.
index
intIndex of the column with the primary ID.
Returns
- int
The ID of the updated database row is returned as an integer.
GetAddedIdentityKey(ref IDbConnection)
The function returns the identity of the last added row to the database
Parameters
connection
IDbConnection The connection used for the update
Returns
- int
The identity of the last added row
Remarks
Returns an integer - this method will only work on tables with a primary key of type identity (SQL-Server), or Auto (MS-Access)
GetAddedIdentityKey(ref IDbConnection, IDbTransaction?)
The function returns the identity of the last added row to the database
Parameters
connection
IDbConnection The connection used for the update
transaction
IDbTransaction The transaction used for the update
Returns
- int
The identity of the last added row
Remarks
Returns an integer - this method will only work on tables with a primary key of type identity (SQL-Server), or Auto (MS-Access)
GetCustomDatabaseConnectionProvider()
Gets the custom database connection provider.
Returns
GetParam(string, DbType, int, string)
Gets current parameter from database.
public static IDbDataParameter GetParam(string paramName, DbType paramType, int paramSize, string paramSourceColumn)
Parameters
Returns
- IDb
Data Parameter Current parameter as IDbDataParameter object.
GetParam(string, DbType, int, string, object?)
Gets current parameter from database.
public static IDbDataParameter GetParam(string paramName, DbType paramType, int paramSize, string paramSourceColumn, object? paramValue)
Parameters
Returns
- IDb
Data Parameter Current parameter as IDbDataParameter object.
InsertRows(DataTable)
Bulk inserts the given data into the database.
Parameters
data
DataTable Data table specifying the data to insert.
Exceptions
- Argument
Null Exception data
is null.- Argument
Exception data
has a TableName property which is either null or empty string ordata
contains no columns.
SortListByDataSet(ref DataSet, string, string, string, int)
Sorts the first table in the specified dataset.
public static string SortListByDataSet(ref DataSet dataSet, string dataSetPrimaryId, string dataSetSort, string direction, int inputPrimaryId)
Parameters
dataSet
DataSet The dataset to be sorted
dataSetPrimaryId
stringName of the column with the primary id in the dataset.
dataSetSort
stringName of the column, the dataset should be sorted by.
direction
stringThe direction the selected row should be moved ("up" or "down").
inputPrimaryId
intThe primary ID of the datarow that needs to be moved up or down.
Returns
Remarks
The table is sorted according to the specified column.
SqlBool(bool)
Returns a Boolean in the appropriate database format.
Parameters
value
booltrue
orfalse
.
Returns
- string
True or False as strings for Access solutions, or 0 or 1 for SQL solutions
Remarks
The returned value is based on the database type set up for the particular solution. Used only for building sql strings, not for DataRows.
SqlBool(int)
Returns a Boolean in the appropriate database format.
Parameters
value
intInteger representing a Boolean. 1 = True, 0 = False.
Returns
- string
True or False as strings for Access solutions, or 0 or 1 for SQL solutions
Remarks
The returned value is based on the database type set up for the particular solution. Used only for building sql strings, not for DataRows.
SqlDate(DateTime)
Returns a date in the appropriate database format.
Parameters
dateTime
DateTime Date as DateTime
Returns
- string
Returns a string representation of the sqldate.
Remarks
The string format is based on the database type set up for the particular solution.
SqlDate(DateTime, bool)
Returns a date in the appropriate database format.
Parameters
dateTime
DateTime Date as DateTime
skipTime
boolIndicates whether to skip the time part of the date
Returns
- string
Returns a string representation of the sql date.
Remarks
The string format is based on the database type set up for the particular solution.
SqlDate(string)
Returns a date in the appropriate database format.
Parameters
dateTime
stringThe date time as a string.
Returns
- string
Returns a string representation of the sql date.
Remarks
The string format is based on the database type set up for the particular solution.
SqlDatePart(string)
Returns a DatePart abbreviation for the appropriate database.
Parameters
part
string
Returns
- string
Returns a string with the DatePart abbreviation, e.g. "yy" or "yyyy" etc.
Remarks
The abbreviation is based on the database type set up for the particular solution.
SqlEscapeInjection(string, bool)
Strips a string of all SQL-commands used to create SQL-injection.
Parameters
text
stringThe text being checked
escapeApostrophes
boolValue indicating whether to escape single apostrophes by replacing them with double apostrohpes.
Returns
Remarks
This function must be used before user input is inserted into SQL-strings.
SqlString(string)
Returns a string quoted with '' for Access and N'' (Unicode) for SQL-Server.
Parameters
value
stringThe string to quote
Returns
Remarks
The string format is based on the database type set up for the particular solution.
SqlWeekday(string)
Returns a string in the appropriate database format.
Parameters
dateTime
string
Returns
TableExists(string)
Helper method to determine whether a table with the given name exists in the given database.
Parameters
tableName
stringName of the table.
Returns
UpdateDateTimeValue(ref object, DateTime)
Updates the DateTime value if the difference between dates is more than or equal 2 milliseconds.
Parameters
Returns
- bool
true
if update was made, otherwsiefalse
Remarks
The .NET has a DateTime resolution to 100th of a nanosecond while SQL Server datatime only has one to 100th of a millisecond.