Dynamicweb 8 Documentation
CreateDataSet(String,IDbConnection) Method
Example 

The SQL specifiyng the data to return in dataset
Existing database connection.
Creates a System.Data.DataSet with data returned by the passed SQL statement from the specfied database.
Syntax
'Declaration
 
Public Overloads Shared Function CreateDataSet( _ 
   ByVal sql As String, _ 
   ByVal connection As IDbConnection _ 
) As DataSet
public static DataSet CreateDataSet( 
   string sql,
   IDbConnection connection 
)

Parameters

sql
The SQL specifiyng the data to return in dataset
connection
Existing database connection.

Return Value

A disconnected System.Data.DataSet instance with data.
Remarks
Since this is a disconnected dataset, no updates are possible. If you want to obtain an updatable dataset use the DataManager.
Example
Create a datasetCreate a dataset
using System.Data;

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

            //Create dataset on alternate database
            var myDataset2 = Database.CreateDataSet("SELECT TOP 10 * FROM AccessUser", "Access.mdb");

            //Loop rows in dataset
            foreach (DataRow row in myDataset.Tables[0].Rows)
            {
                var userId = Input.FormatInteger(row["AccessUserID"]);
            }
        }
    }
}
Public Class DatabaseCreateDataset
    Public Sub DatasetSample()

        'Create dataset on the default database
        Dim myDataset As DataSet = Database.CreateDataset("SELECT TOP 10 * FROM Page")

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

        'Create dataset on alternate database
        Dim myDataset2 As DataSet = Database.CreateDataset("SELECT TOP 10 * FROM AccessUser", "Access.mdb")

        'Loop rows in dataset
        For Each row As DataRow In myDataset.Tables.Item(0).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