Dynamicweb 8 Documentation
ExecuteNonQuery(String,Boolean) Method
Example 

The SQL to execute against the database
if set to true [transaction].
Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
Syntax
'Declaration
 
Public Overloads Shared Function ExecuteNonQuery( _ 
   ByVal sql As String, _ 
   ByVal transaction As Boolean _ 
) As Integer
public static int ExecuteNonQuery( 
   string sql,
   bool transaction 
)

Parameters

sql
The SQL to execute against the database
transaction
if set to true [transaction].

Return Value

The number of rows affected.
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.
Example
Using ExecuteNonQueryUsing ExecuteNonQuery
namespace Dynamicweb.Examples.CSharp
{
    class DatabaseExecute
    {

        public void ExecuteSample()
        {
            //ExecuteScalar
            var pageCount = Input.FormatInteger(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"));

            //ExecuteScalar on alternate database
            var userCount = Input.FormatInteger(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", "Access.mdb");

        }

    }
}
Public Class DatabaseExecute
    Public Sub ExecuteSample()

        'ExecuteScalar
        Dim pageCount As Integer = Input.FormatInteger(Database.ExecuteScalar("SELECT COUNT(PageID) FROM Page"))

        'ExecuteScalar on alternate database
        Dim userCount As Integer = Input.FormatInteger(Database.ExecuteScalar("SELECT COUNT(AccessUserID) FROM AccessUser"))

        'ExecuteNonQuery
        Dim numberOfPagesDeleted As Integer = Database.ExecuteNonQuery("DELETE FROM Page WHERE PageID < 101")

        'ExecuteNonQuery on alternate database
        Dim numberOfUsersDeleted As Integer = Database.ExecuteNonQuery("DELETE FROM AccessUser WHERE AccessUserID < 101", "Access.mdb")

    End Sub
End Class
Requirements

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

See Also

Reference

Database Class
Database Members
Overload List

Send Feedback