Dynamicweb 8 Documentation
CreateDataTable(String) Method
Example 

The SQL specifiyng the data to return in System.Data.DataTable
Creates a System.Data.DataTable with data returned by the passed SQL statement.
Syntax
'Declaration
 
Public Overloads Shared Function CreateDataTable( _ 
   ByVal sql As String _ 
) As DataTable
public static DataTable CreateDataTable( 
   string sql 
)

Parameters

sql
The SQL specifiyng the data to return in System.Data.DataTable

Return Value

A disconnected System.Data.DataTable instance with data.
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 System.Data.DataTable, no updates are possible.
Example
Create a DataTableCreate a DataTable
using System.Data;

namespace Dynamicweb.Examples.CSharp
{
    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 = Input.FormatInteger(row["PageID"]);
            }

            //Create DataTable on alternate database
            DataTable myDataTable2 = Database.CreateDataTable("SELECT TOP 10 * FROM AccessUser", "Access.mdb");

            //Loop rows in DataTable
            foreach (DataRow row in myDataTable.Rows)
            {
                var userId = Input.FormatInteger(row["AccessUserID"]);
            }
        }
    }
}
Public Class DatabaseCreateDataTable
    Public Sub DataTableSample()

        'Create DataTable on the default database
        Dim myDataTable As DataTable = Database.CreateDataTable("SELECT TOP 10 * FROM Page")

        'Loop rows in DataTable
        For Each row As DataRow In myDataTable.Rows()
            Dim pageId As Integer = Input.FormatInteger(row.Item("PageID"))
        Next

        'Create DataTable on alternate database
        Dim myDataTable2 As DataTable = Database.CreateDataTable("SELECT TOP 10 * FROM AccessUser", "Access.mdb")

        'Loop rows in DataTable
        For Each row As DataRow In myDataTable.Rows()
            Dim userID As Integer = Input.FormatInteger(row.Item("AccessUserID"))
        Next
    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