Dynamicweb 8 Documentation
CreateDataSet(String,IDbConnection,Boolean) Method
Example 

The SQL specifiyng the data to return in System.Data.DataSet
Existing database connection.
Set to true if the returned dataset should contain schema information on table names, column names and types etc.
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, _ 
   ByVal withSchema As Boolean _ 
) As DataSet
public static DataSet CreateDataSet( 
   string sql,
   IDbConnection connection,
   bool withSchema 
)

Parameters

sql
The SQL specifiyng the data to return in System.Data.DataSet
connection
Existing database connection.
withSchema
Set to true if the returned dataset should contain schema information on table names, column names and types etc.

Return Value

A disconnected System.Data.DataSet instance with data.
Remarks
Since this is a disconnected System.Data.DataSet, no updates are possible. If you want to obtain an updatable System.Data.DataSet use the DataManager. Adds a System.Data.DataTable named "Table" to the specified System.Data.DataSet and configures the schema to match that in the data source.
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