Dynamicweb 8 Documentation
CreateDataTable(String,String) Method
Example 

The SQL specifiyng the data to return in System.Data.DataTable
Name of the MS Access database to get the data from (I.e. "Access.mdb" in /Database directory). Ignored if solution is running MS SQL-Server
Creates a System.Data.DataTable with data returned by the passed SQL statement from the specfied database.
Syntax
'Declaration
 
Public Overloads Shared Function CreateDataTable( _ 
   ByVal sql As String, _ 
   ByVal database As String _ 
) As DataTable
public static DataTable CreateDataTable( 
   string sql,
   string database 
)

Parameters

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

Return Value

A disconnected System.Data.DataTable instance with data.
Remarks
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